Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
493 Users Online NOW
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi







Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (5)


Automatically start a service after using /Install or /Uniinstall switchFormat this article printer-friendly!Bookmark function is only available for registered users!
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:
5968
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.





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
Update
    brian (Aug 24 2004 1:14AM)

This doesn't seem to work with Delphi 7 and XP.
Causes an Exception or Runtime error 216.
Respond

parasitage du site aifind
    jldroguet (May 19 2004 10:48PM)

ne sait plus rentrer dans aucun programme
Respond

to make it perfect...
    Andreas Schmidt (May 20 2003 11:53AM)

... we use FindCmdLineSwitch:

  // local helper function
  function FindSwitch(const Switch: string): Boolean;
  begin
    Result := FindCmdLineSwitch(Switch, ['-', '/'], True);
  end;

initialization

if FindSwitch('uninstall') then
  begin
    WinExec('cmd.exe /c net stop myservice',sw_hide);
    sleep(3000);
  end;

finalization
  if FindSwitch('Install') then
    WinExec('cmd.exe /c net start myservice',sw_hide);
end.
Respond

RE: to make it perfect...
Alex (Aug 23 2004 5:25AM)

Thank you, saves me time developing my service :)
Respond

RE: to make it perfect...
Lyle Martin (May 27 2005 9:52PM)

I added the helper local function and it still does not work for me with Delphi 7 Pro and XP.  The service starts up, runs for a few seconds and then dies.

When I reboot the machine, the service starts up and runs fine.

Any suggestions?  This is going to be a real pain to deploy this service if I tell them they have to reboot every time they want to restart the service.

Thanks,
-Lyle

Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
D. Souchard
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)