Warm tip: This article is reproduced from stackoverflow.com, please click
c++ windows activation

Error when activating windows from c++ program

发布于 2020-03-27 10:31:48

I am creating a windows utility that, in part, allows the user to activate windows. when I run the command slmgr /ato with system() I get the error "0x80004001 Not implemented (SWbemObjectEx)". When I try to execute the same command from cmd it works fine. It should also be noted that it doesn't fail every time, half of the time it works perfectly fine. At first I thought that perhaps I was executing the commands too quickly in succession, but adding a delay doesn't seem to make a difference.

void activateWindows(char* key)
{
    EnableWindow(Main_activate_win, false);
    char cmd[41];
    sprintf(cmd, "slmgr /ipk %s", key);
    system(cmd);
    //Sleep(5000);
    system("slmgr /ato");
    EnableWindow(Main_activate_win, true);
}

EDIT: it seems that it only fails in this way when it is installing onto a machine that previously had a different version of windows installed.

Questioner
Zachary Schroeder
Viewed
80
Zachary Schroeder 2019-07-03 23:53

OK, I finally figured it out. I was compiling my program as a 32 bit application because I was having trouble when compiling it as 64 bit initially. Windows doesn't let 32 bit applications access 64 bit libraries and executables, and apparently that also goes for any child processes created by them. My guess is that the slmgr.vbs script was trying to access a 64 bit file or library and it couldn't find it hence the "not implemented" error message. I recompiled as a 64 bit app and it seems to be working OK now. This one definitely tested my patience.