The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

"sc" command (sc.exe) and Windows XP

I am building an installer that needs to establish and start a service on installation, and shut down and delete the service on uninstallation.

sc, of course, is the command line interface to Windows service management. sc.exe seems to have been installed on several XP SP2 installations I have. But online references refer to it as being a part of the "resource kit".

The reason I ask is: I am building an installer, and I want to know if sc.exe will always exist on the user's system. We are restricting installation only to Windows XP based systems.

If I can't start and stop the service from the command line, I will need to write a small helper application.

Thanks.
Bored Bystander Send private email
Friday, April 07, 2006
 
 
Is "net start|stop serviceName" not adequate?
Chris Altmann
Friday, April 07, 2006
 
 
I'm aware of the built in NET commands. But there does not seem to be a way to create or remove a service with NET. SC does all of these things (start, stop, add, remove.)
Bored Bystander Send private email
Friday, April 07, 2006
 
 
Looking at the DLL Help database it says it is installed with XP - SP1 and SP2

http://support.microsoft.com/dllhelp/?dlltype=file&l=55&alpha=sc.exe&S=1&x=14&y=12
DJ
Friday, April 07, 2006
 
 
I did something similar recently and I seem to remember that sc.exe can run standalone (ie. it doesn't have to be installed with an installer) and so I just put it in my installation directory and ignored whether it existed already.
cja Send private email
Friday, April 07, 2006
 
 
Thanks to all of you... that helps a lot. I'll probably do what cja suggests.
Bored Bystander Send private email
Friday, April 07, 2006
 
 
Most of the Installers have the ability to invoke win32 functions; so check for the win32 functions that are related with service management. if you are using InnoSetup, have a look at the forums for the code snippets. Three years back I was using innosetup to start and stop services.

Friday, April 07, 2006
 
 
Or if it's a .net service, run installutil.exe
example Send private email
Friday, April 07, 2006
 
 
Nah, it's a Win32 service. All I can count on is XP SP1 or higher.
Bored Bystander Send private email
Friday, April 07, 2006
 
 
It IS InnoSetup, and I just stumbled into the "code" part of writing installers. Yes, I will probably move the sc invocations out and replace with API calls. Thanks for the idea!
Bored Bystander Send private email
Saturday, April 08, 2006
 
 
in delphi you can get away with:

yourservice.exe /INSTALL

and

yourservice.exe /UNINSTALL

use Net.exe to start and stop.
Mike johnson Send private email
Saturday, April 08, 2006
 
 
Now, if you were using MSI it would be as simple as typing the service name and setting a couple of options (This is TRUE believe it or not - It's one thing that MSI does very well). But hey - you want to do it the hard way don't you


Apart from that search for service control manager in MSDN. There's a whole slew of Win32 functions. Start here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/createservice.asp
MSI Guru
Saturday, April 08, 2006
 
 
Do you need to wait for the service to finish starting before continuing with the installation, or is async OK?

- how would you acheive sunchronous execution when calling net start?
Free Thinker
Saturday, April 08, 2006
 
 
Just add an installer class to the .NET service and add command line paramters to /install and /uninstall it.
Aaron Flynt
Saturday, April 08, 2006
 
 
It's really easy to write a service installer using the Win32 API. Look at the exports available from advapi32.dll, such as CreateService, OpenSCManager, CloseServiceHandle, OpenService, DeleteService, ControlService, QueryServiceStatus, StartService.

It's all well documented and easy to do.
J
Sunday, April 09, 2006
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz