|
| Automatically start a service after using /Install or /Uniinstall switch | 
|
|---|
Product: Delphi 5.x (or higher) | Category: System | Skill Level:
 | Scoring:  | Last Update: 05/19/2003 | Search Keys: delphi delphi3000 article borland vcl code-snippet service NTService autostart service-install Install-service serice-uninstall uninstall-service autostop stop-service start-service | Times Scored: 9 | Visits: 6555 | Uploader: Brian Gochnauer Company: | Reference: N/A | | | Question/Problem/Abstract:
Have you ever wished that the service would also start after installing the service not just install itself. | Answer:
// In the service unit add these statements before the 'end.' statement.
// To automatically start or stop the service during install or uninstall
// Tested only on Win2k and WinXP
// Change the 'myservice' in both WinExec statements to your own service name.
initialization
if (ParamCount >= 1) and (CompareText('/uninstall',ParamStr(1))=0) then
begin
WinExec('cmd.exe /c net stop myservice',sw_hide);
sleep(3000);
end;
finalization
if (ParamCount >= 1) and (CompareText('/Install',ParamStr(1))=0) then
WinExec('cmd.exe /c net start myservice',sw_hide);
end.
|
|