[fpc-pascal]Windows ShutDown Privilege
mpdj at btinternet.com
Fri Dec 6 07:46:47 CET 2002
I'm trying to shut down windows. I know it should be simple, but
for some reason, I can't get my application to have shutdown privileges.
The procedure I'm using is this...
hToken : Handle;
tkp : TOKEN_PRIVILEGES;
h : PWORD;
If OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES + TOKEN_QUERY, hToken) then Begin
LookupPrivilegeValue(nil, SE_SHUTDOWN_NAME, tkp.Privileges.Luid);
AdjustTokenPrivileges(hToken, False, @tkp, SizeOf(tpk), nil , at h);
ExitWindowsEx (EWX_SHUTDOWN, 0);
OpenProcessToken returns TRUE, so does LookUpPriviliegeValue and
Problem is, ExitWindowsEX returns FALSE with the error that I don't
have the ShutDown privilege. I can't for the life of me spot the
problem. I'm sure it's going to be something stupid I've missed, but
I'm blind to it. It's failed on both my Win2000 and XP machines.
If anyone has a spare few seconds to see if they can spot my mistake,
I'd be very grateful.
More information about the fpc-pascal