Shut down Windows 2000 program

  • Thread starter Thread starter mike4ty4
  • Start date Start date
M

mike4ty4

Hi.

How would one go about writing a program (in C/C++) that would shut
down/reboot Windows 2000?
 
Whoops! Sorry about the multiple posting. I'd been clicking the "back"
button, hoping to go back to the Google Groups search page -- but no,
I'd been actually hitting "back" to the posting submittal url and that
seemed to have cause the resubmit. Argh.
 
HANDLE hToken;
LUID ShutDownValue;
TOKEN_PRIVILEGES tkp;

if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
&hToken))
{
//AfxMessageBox("OpenProcessToken failed");
return FALSE;
}
// // Enable the SE_SHUTDOWN_NAME privilege

if (!LookupPrivilegeValue((LPSTR) NULL,
SE_SHUTDOWN_NAME,
&ShutDownValue))
{
//AfxMessageBox("LookupPrivilegeValue failed");
return FALSE;
}
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Luid = ShutDownValue;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken,
FALSE,
&tkp,
sizeof(TOKEN_PRIVILEGES),
(PTOKEN_PRIVILEGES) NULL,
(PDWORD) NULL);

ExitWindowsEx(EWX_REBOOT|EWX_FORCE,0);
 
Back
Top