請各位C++的高手幫我看一下這段程式有無錯誤

請各位先進幫我看一下以下這段程式有沒有錯誤 還有執行的結果是什麼 #include <windows.h> void ExitWIN(UNIT command); int main() { cout << \"Enter command (shutdown = 1, reboot = 2): \"; int opt; cin >> opt; if (opt == 1) { ExitWIN(EWX_SHUTDOWN); } else if (opt == 2) { ExitWIN(EWX_REBOOT); } ... show more 請各位先進幫我看一下以下這段程式有沒有錯誤
還有執行的結果是什麼

#include <windows.h>

void ExitWIN(UNIT command);

int main()
{
cout << \"Enter command (shutdown = 1, reboot = 2): \";
int opt;
cin >> opt;
if (opt == 1) {
ExitWIN(EWX_SHUTDOWN);
} else if (opt == 2) {
ExitWIN(EWX_REBOOT);
}

return 0;
}

void ExitWIN(UNIT command)
{
HANDLE hToken;
TOKEN_PRIVILEGES tkp;

// open and check the privileges for to perform the actions
if ( OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
&hToken) ) {

LookupPrivilegeValue( NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

// adjust the privilege to perform the action
if(AdjustTokenPrivileges( hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0)) {
ExitWindowsEx(command | EWX_FORCE, 0);
}
}

int err = GetLastError();
// if any error occurs the report to the user
if (err) {
cerr << \"Error restarting windows\" << endl;
}
}
1 answer 1