Hvorfor kalder du ikke bare ExitWindowsEx fra dit hovedprogram?
Se:
http://windowssdk.msdn.microsoft.com/en-us/library/ms723147(VS.80).aspxEt komplet program der lukker computeren:
BOOL SetPrivilege()
{
HANDLE Token;
LUID luid;
TOKEN_PRIVILEGES tp;
if(!OpenProcessToken(GetCurrentProcess(), TOKEN_WRITE, &Token))
{
printf("OpenThreadToken error: %u\\n", GetLastError());
return FALSE;
}
if(!LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &luid))
{
printf("LookupPrivilegeValue error: %u\\n", GetLastError());
return FALSE;
}
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(Token,
FALSE,
&tp,
sizeof(TOKEN_PRIVILEGES),
(PTOKEN_PRIVILEGES )NULL,
(PDWORD )NULL);
if (GetLastError() != ERROR_SUCCESS)
{
printf("AdjustTokenPrivileges error: %u\\n", GetLastError());
return FALSE;
}
return TRUE;
}
int main()
{
if(!SetPrivilege())
{
printf("Failed to set privilege\\n");
return 0;
}
if(!ExitWindowsEx(EWX_POWEROFF, 0))
{
printf("Error: %d\\n", GetLastError());
}
}