uses
ComObj,
ActiveX, JwaWinbase, JwaWtsApi32;
{$R *.DFM}
procedure ServiceController(CtrlCode: DWORD);
stdcall;
begin
ServiceExample.Controller(CtrlCode);
end;
function TServiceExample.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;
procedure TServiceExample.ServiceExecute(Sender: TService);
begin
Timer1.Enabled := True;
while not Terminated
do
ServiceThread.ProcessRequests(True);
// wait for termination
Timer1.Enabled := False;
end;
procedure TServiceExample.Timer1Timer(Sender: TObject);
const
ProgramName = '
C:\myTestproject1.exe';
var
hToken: THandle;
StartupInfo: Windows.TStartupInfo;
ProcessInfo: Windows.TProcessInformation;
res: boolean;
begin
Windows.GetStartupInfo(StartupInfo);
if WTSQueryUserToken(WtsGetActiveConsoleSessionID, hToken)
then
begin
res := Windows.CreateProcessAsUser(hToken, ProgramName,
nil,
nil,
nil, False, CREATE_NEW_CONSOLE,
nil,
nil, StartupInfo, ProcessInfo);
if res
then
WaitForSingleObject(ProcessInfo.hProcess,INFINITE);
end;
end;