Registriert seit: 6. Apr 2011
Ort: Berlin
3.070 Beiträge
Delphi 10.4 Sydney
|
AW: Windows 10 - GetModuleHandle('USER32.DLL') & LockWorkStation funktioniert nicht
8. Nov 2017, 17:11
Mal so runtergetippt und ungetestet:
Delphi-Quellcode:
function WTSQueryUserToken(SessionId: ULONG; phToken: PDWORD): BOOL; stdcall; external wtsapi32;
function WTSGetActiveConsoleSessionId: DWORD; stdcall; external kernel32;
procedure Test;
var
SessionId: DWORD;
UserTokenHandle: DWORD;
StartInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
IsCreated: BOOL;
begin
UserTokenHandle := 0;
SessionId := WTSGetActiveConsoleSessionId;
if WTSQueryUserToken(SessionId, @UserTokenHandle) then
begin
FillChar(StartInfo, SizeOf(StartInfo), 0);
StartInfo.cb := SizeOf(StartInfo);
FillChar(ProcessInfo, SizeOf(ProcessInfo), 0);
IsCreated := CreateProcessAsUser(
UserTokenHandle,
'rundll32.exe',
'rundll32.exe user32.dll,LockWorkStation',
nil, nil, False, 0, nil, nil,
StartInfo, ProcessInfo);
if not IsCreated then
RaiseLastOSError;
end
else
RaiseLastOSError;
end;
|
|
Zitat
|