Created
June 29, 2021 01:17
-
-
Save viniciusmelocodes/0a7d611abfd3b361b8ba70ce95791edd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Rodar processo como usuário | |
function WTSQueryUserToken(SessionId: ULONG; var phToken: THandle): BOOL; stdcall; external 'Wtsapi32.dll'; | |
procedure executarApp(appName: string); | |
var | |
hToken: THandle; | |
StartupInfo: TStartupInfo; | |
ProcessInfo: TProcessInformation; | |
res: boolean; | |
begin | |
GetStartupInfo(StartupInfo); | |
if WTSQueryUserToken(WtsGetActiveConsoleSessionID, hToken) then | |
begin | |
res := CreateProcessAsUser(hToken, PWideChar(appName), nil, nil, nil, False, CREATE_NEW_CONSOLE, nil, nil, StartupInfo, ProcessInfo); | |
if res then | |
WaitForSingleObject(ProcessInfo.hProcess, INFINITE); | |
end; | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment