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.