-
-
Save viniciusmelocodes/3934724c645584dfbee55d186e9ec912 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