Click to See Complete Forum and Search --> : Problem with InitiateSystemShutdown


Rich Scales
October 13th, 1999, 04:48 PM
I've been having trouble with the InitiateSystemShutdown function. It keeps returning a value of 0 (meaning that it failed). Here's the code I've been using.

InitiateSystemShutdown(NULL, NULL, 0, FALSE, TRUE)



I used GetLastError() to see whats going on, but theres no error number 6683144. Any ideas? Any help would be appreciated. Thanks.

Rich

senthil
October 13th, 1999, 05:41 PM
You can use the below code to shut down the system
I stole the below code from MSDN library.

HANDLE hToken;
TOKEN_PRIVILEGES tkp;

// Get a token for this process.

if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
error("OpenProcessToken");

// Get the LUID for the shutdown privilege.

LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
&tkp.Privileges[0].Luid);

tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

// Get the shutdown privilege for this process.

AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES)NULL, 0);

// Cannot test the return value of AdjustTokenPrivileges.

if (GetLastError() != ERROR_SUCCESS)
error("AdjustTokenPrivileges");

// Shut down the system and force all applications to close.

if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0))
error("ExitWindowsEx");
For more information about setting security privileges, see Privileges.

May 19th, 2000, 10:13 AM
Problem: Process initiating shutdown without machine being logged on.

With the given solution, it is not possible for the process to initiate a shutdown if the machine is not logged on. How can a process which is started by a service at startup, initiate a shutdown without being logged on. Please note that the service starting this process has all administrative permissions.

Regards
krishnan