Created
May 13, 2016 10:52
-
-
Save JordiCorbilla/f01c2d34c20e7d2b60fddf60b558ab0c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment