Click to See Complete Forum and Search --> : Emergency shutdown


Didier VOINNET
June 20th, 2001, 10:49 AM
Microsoft GINA offers emergency shutdown functionality (see http://support.microsoft.com/support/kb/articles/q279/1/34.asp).
How can I implement this in my GINA?

Alex Fedotov
June 21st, 2001, 05:05 AM
A quick look at msgina.dll import table shows a call to undocumented
NtShutdownSystem function. According to "Windows NT/2000 Native API
Reference" by Gary Nebbet, this function does not notify services
and user applications before it shuts down the system.

The function prototype is as follows:


NTSYSAPI
NTSTATUS
NTAPI
NtShutdownSystem(
IN SHUTDOWN_ACTION Action
);

typedef enum _SHUTDOWN_ACTION {
ShutdownNoReboot,
ShutdownReboot,
ShutdownPowerOff
}SHUTDOWN_ACTION;




The function is exported from ntdll.dll.

Didier VOINNET
June 29th, 2001, 11:48 AM
Using NtShutdownSystem(ShutdownNoReboot), I got the error 1314 (A required privilege is not held by the client.) even if I have SE_SHUTDOWN_NAME privilege.

Must I have to use another function that AdjustTokenPrivileges?

Alex Fedotov
July 3rd, 2001, 08:12 PM
I've just tried it and it works fine on my system. Here is my code:


HANDLE hToken;
if (OpenProcessToken(GetCurrentProcess(),
TOKEN_QUERY|TOKEN_ADJUST_PRIVILEGES, &hToken))
{
TOKEN_PRIVILEGES tkp;

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

tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, 0);
CloseHandle(hToken);
}

NtShutdownSystem(ShutdownNoReboot);