Abaksoft Posted October 7, 2018 Share Posted October 7, 2018 Good moorning Friends, Just wanted to advise. - ShellExecute works fine on VCL Desktop applications only. - ShellExecute does'nt work on a Windows Service ! Because of Windows Security (Session0, Session 1) introduced after Windows 7 use instead CreateProcessAsUser like this : procedure TMainForm.RunApp(cmdLine, WorkDir: String); var hToken: THandle; StartupInfo: TStartupInfo; ProcessInfo: TProcessInformation; res: boolean; begin GetStartupInfo(StartupInfo); if WTSQueryUserToken(WtsGetActiveConsoleSessionID, hToken) then begin { 1. For an application.exe (exemple : NotePad.exe) res := CreateProcessAsUser(hToken, PChar(Path_appName), PChar(cmdLine), nil, nil, False, CREATE_NEW_CONSOLE, nil, PChar(WorkDir), StartupInfo, ProcessInfo); } {2. For a DOS command line (Example FireBird : cmdLine:='gbak.exe -user sysdba -pas masterkey -b -nt "D:\Base.fdb" "D:\toto.fbk" '; WorkDir:='C:\Program Files\Firebird\Firebird_2_5\bin'; } res := CreateProcessAsUser(hToken, Nil, PChar('cmd.exe /C ' + cmdLine), nil, nil, True, CREATE_NO_WINDOW, nil, PChar(WorkDir), StartupInfo, ProcessInfo); if res then WaitForSingleObject(ProcessInfo.hProcess,INFINITE); end; end; That will save you much time Regards. 2 Quote Link to comment Share on other sites More sharing options...
Tokay Posted October 8, 2018 Share Posted October 8, 2018 I think that you can just analize returned value of the ShellExecute to understand what happend https://docs.microsoft.com/en-us/windows/desktop/api/shellapi/nf-shellapi-shellexecutea Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.