Archive: Windows Service


Windows Service
Hi,
I wish to find out if there is any way I could start a windows service through the installer?
Basically, I am looking at getting my program (after installation) to start up by itself whenever Windows startup.
Thanks.


You don't need a service for that... Either put a shortcut in $SMSTARTUP or write to the registry in the appropriate place as explained at this MSDN page: http://msdn.microsoft.com/library/de...istry_keys.asp


If the service is installed you can also start a service using the net command (Windows NT and later only maybe).

net start <servicename>
net stop <servicename>

Without the angle brackets.


Hi,

As you mentioned the use of net start, may I know how should I create or what command should I include in my .nsi file such that I could use this net start command to start my program?

Thanks.:)


net is a command present on 2K systems and above and maybe some NT systems too (NT4?) so you just run it like any other system command. net does many things other than manipulate services, net start and net stop are two commands for services that you will want to use.

Here are some examples :
Exec "net stop servicename"
ExecWait "net stop servicename"
nsExec::Exec "net stop servicename"
nsExec::ExecToLog "net stop servicename"
nsExec::ExecToStack "net stop servicename"

I'm not sure if this will work:

ExecShell "net stop servicename"


Hi,

Thanks for your respond but I guess I didnt make myself clear.

I need to know how to register my program to a windows service such that I could use those Exec "net start test" and so on...

I need to know how to register my program in my .nsi file. Not how to use the net command in my script.

Apologise for that confusion. Thanks.


I'm not sure I or anyone can answer that. Is this a program you have written yourself? If so you should have coded a way for the service to register itself. Is it written by someone else? If so they should have provided a means to register it. Is this program actually not designed as a service program but you want to run it as a service anyway? That's a different problem entirely.


Assuming what you want to "register" as a service is actually designed that way...

Included in the .NET Framework SDK there is a utility named "InstallUtil.exe". This utility is used to execute installers on a given assembly. In part 1 step 2, we discussed how to use the ServiceInstaller and ServiceProcessInstaller to install our service on the desired machine. Executing "InstallUtil.exe" on our Windows Service assembly will (hopefully) install the Windows Service.

To install our service from the command line type:


installutil scheduler_net.exe


and to uninstall it, add the "/u" parameter:

installutil scheduler_net.exe /u


Finally, launch the services plug-in in the Microsoft Management Console and start the service.
Taken from http://www.15seconds.com/issue/021015.htm

Apparently this is the scenerio:

"this program actually not designed as a service program but I want to run it as a service anyway....."

Would be nice to know if it is possible...Thanks.


Try looking into FireDaemon or SrvAny (the latter is an NT Resource Kit tool I think). Both of these programs allow any executable to run as a service, FireDaemon is more user friendly and more capable in my experience.

You must remember however that since the program wasn't designed to work as a service it may not run entirely as expected when using these tools.


Windows Service
How is it possible to reboot a computer and have a Shoutcast relay server auto start?


You could add a value to the Run or RunOnce keys in the registry.


Registrey Keys
OK, Sunjammer
how would I do that

thanx for your reply


How To Do It ...
The Run and RunOnce keys exist in two places, in the per user configurations in the registry, and in the local machine configuration... I'd suggest you want it in the latter, that is :-

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce


If you want the Shoutcast Relay Server to run *every* time the computer reboots then you'll want to add a value to the Run key, otherwise if it's just the once you want it to happen use the RunOnce key instead :-

WriteRegStr HKLM \
"SOFTWARE\Microsoft\Windows\CurrentVersion\Run" \
"ShoutCastRelayServer" "c:\path\to\relay\server\binary.exe"


The ShoutCastRelayServer bit is just a name, you can put anything there.

If you need to specify arguments to the shoutcast server you'll need to do it like this:-

WriteRegStr HKLM \
"SOFTWARE\Microsoft\Windows\CurrentVersion\Run" \
"ShoutCastRelayServer" \
'"c:\path\to\relay\server\binary.exe" /arg /arg /arg'

Tools
Thnx very much SunJammer

Now I have never edited a registry... obviously a backup prior to edit is in order.... any suggestions on tools.... like I use phpmyadmin for database editing, phpedit for script editing.... is there an application to use or just notepad..?

I really want to have all the knowledge possible before jumping into such a fragile area.

many thanx


Have a look at the NSIS related software section in the archive:
http://nsis.sourceforge.net/archive/...=8&instances=0


Adding a value under the Run or RunOnce keys *should* be safe, unless you are specifying a program that for some reason really causes a problem when starting Windows... but I've never encountered that problem myself.