Shutdown...?
This question was already posed some times ago: I just say: ExitWindowsEx().... Look it up in the MSDN , it''S quite easy!
Darn beat me to it!
The Win32 API function: " ExitWindowsEx", although be sure your application has the privilege before invoking it.
[edited by - Xiachunyi on March 6, 2004 11:33:51 AM]
The Win32 API function: " ExitWindowsEx", although be sure your application has the privilege before invoking it.
[edited by - Xiachunyi on March 6, 2004 11:33:51 AM]
Nothing happens here''s my code:
//---------------------------------------------------------------------------#include <iostream.h>#include <windows.h>#include <windowsx.h>int main(void){ ExitWindowsEx(EWX_SHUTDOWN, NULL); return(0);}
To shut down or restart the system, the calling process must use the AdjustTokenPrivileges function to enable the SE_SHUTDOWN_NAME privilege.
[edited by - Lantz on March 6, 2004 12:06:24 PM]
[edited by - Lantz on March 6, 2004 12:06:24 PM]
quote:Original post by PlayGGY
I would doubt a console application could call it, anyways.
Actually that shouldn''t make any difference, windows does not differ between console apps and regular ones.
You could try something like this (i havent tried it):
HANDLE token;OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &token );TOKEN_PRIVILEGES p;p.PrivilegeCount = 1;p.Privileges[0].Luid = 0;p.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;AdjustTokenPrivileges( token, false, &p, 0, NULL, 0 );CloseHandle( token );
Nothing happpens again. Thsi is th ecode I have so far:
HANDLE token;OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &token );TOKEN_PRIVILEGES p;p.PrivilegeCount = 1;p.Privileges[0].Luid;p.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;AdjustTokenPrivileges( token, false, &p, 0, NULL, 0 );CloseHandle( token );ExitWindowsEx(EWX_POWEROFF, NULL);
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement