Shut down Windows 2000 program

M

mike4ty4

Hi.

How would one go about writing a program (in C/C++) that would shut
down/reboot Windows 2000?
 
M

mike4ty4

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.
 
L

LargeBird

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);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top