View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0000169 | JEDI VCL | 00 JVCL Components | public | 2002-07-15 03:03 | 2002-08-12 14:33 |
Reporter | anonymous | Assigned To | user72 | ||
Priority | normal | Severity | feature | Reproducibility | always |
Status | closed | Resolution | fixed | ||
Product Version | |||||
Target Version | Fixed in Version | ||||
Summary | 0000169: TjvExitWindows : SE_SHUTDOWN_NAME privilege token is not automatically set. | ||||
Description | As described in Win32 reference - "To shut down or restart the system, the calling process must use the AdjustTokenPrivileges function to enable the SE_SHUTDOWN_NAME privilege". TJvExitWindows should enable this privilege for running process automatically. | ||||
Additional Information | Note : In order to use AdjustTokenPrivilege function, the process must open two process tokens --TOKEN_ADJUST_PRIVILEGES and TOKEN_QUERY. OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES + TOKEN_QUERY, hToken) | ||||
Tags | No tags attached. | ||||
|
FWIW, this unit has been removed in 2.0 |
|
I took a look at how this should be done and I think the following code is correct (at least for D6): function JclExitWindows(ExitCode: Cardinal):boolean; const SE_SHUTDOWN_NAME = 2; var hToken:Cardinal; Privs:TTokenPrivileges; ReturnLength:Cardinal; begin if Win32Platform = VER_PLATFORM_WIN32_NT then begin Result := OpenProcessToken(GetCurrentProcess,TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY,hToken) and LookupPrivilegeValue(nil, 'SeShutdownPrivilege', Privs.Privileges[0].luid); if Result then begin with Privs do begin PrivilegeCount := 1; Privileges[0].Attributes := SE_SHUTDOWN_NAME; end; Result := AdjustTokenPrivileges(hToken, false, Privs, sizeof(Privs), nil, ReturnLength); end; if not Result then Exit; end; Result := ExitWindowsEx(ExitCode,0); end; call something like this: if not JclExitWindows(EWX_LOGOFF) then RaiseLastOSError; // RaiseLastWin32Error for D5 BTW, since I didn't find anything similar in JCL I hereby donate the above code for inclusion in JCL (I think JCL is the better place to put it). I even named it according to the JCL rules <g>. |
|
Now in JclMiscel as ExitWindows (see 0000172) |