IPB

Google Frontpage Forums Unattended CD/DVD Guide
> How to run a program as a Service
tain
post Sep 24 2006, 11:44 AM
Post #1


Cyber Ops
Group Icon

Group: Super Moderator
Posts: 3089
Joined: 24-September 05
From: Ft Meade, Maryland, USA
Member No.: 74319
OS: XP Pro x86
Country Flag


I wanted to setup some programs to run as Windows Services but found information on the subject to be scattered around everywhere. So this post is basically for consolidation and clarification but is not focused on unattended installations.

What is a Service?
A Windows Service is automatically started when your system boots. There is no need to logon to the system. Services also are not affected by people logging off. Services automatically recover from program crashes and Standby and Hibernation modes. Windows 9x/ME do not have a Service facility. Installing software as a Service requires Administrator permissions.

What are the options for running a program as a Service?
  1. sc.exe
    This is Microsoft software and is installed by default on XP and 2003. It is probably the best and easiest method but it won't work if the target executable was not programmed to run as a Service. This rules it out for what many people are trying to do since most programs that are designed ro run as a Service have that option included somewhere in the application. sc.exe is useful for the Unattended crowd, though.

    The syntax for sc.exe is worth noting. This will NOT work:
    QUOTE
    sc create YourServiceName binPath="c:\Program Files\directory\appname.exe"
    But this WILL work (note the space after the =):
    QUOTE
    sc create YourServiceName binPath= "c:\Program Files\directory\appname.exe"

    Two other useful options, with the same syntax as above, are:
    CODE
    type= <own|share|interact|kernel|filesys|rec>
          (default = own)
    start= <boot|system|auto|demand|disabled>
          (default = demand)

    You can use these commands for more details:
    CODE
    sc /?
    CODE
    sc create /?

  2. instsrv.exe and srvany.exe
    This is Microsoft software but was published as part of the Resource Kits. You can download the files here or here. Thanks to tacktech.com for providing the fileset.

    Instrsrv.exe installs the Service but srvany.exe is the real gem here as it is a wrapper that allows any software to be run as a Service. This method worked great for me but does require manual registry edits.

    Here is a quick summary of the steps invloved but you can find more complete instructions at Microsoft's KB page or TackTech's page with great screenshots.
    1. Unpack the fileset to a folder of your choice. srvany.exe needs to remain on your system for this method to work, so put it somewhere like Program files where you won't mind leaving it around. I use C:\Program Files\services in this example.
    2. Install the Service with a command like this:
      CODE
      C:\Program Files\services\Instsrv.exe YourServiceName C:\Program Files\services\Srvany.exe
    3. Using a registry editor, find this key:
      CODE
      HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\YourServiceName
    4. Add a new sub-key called Parameters.
    5. In the Parameters key, create a new string value named Application.
    6. Set the value data of Application to the full path of the executable file that you want the service to launch. For example, C:\WINNT\notepad.exe.
    7. Using the Services console, find your new service and make any necessary property edits. This dialog will allow you to set the startup type, logon method, and program failure options.
    One problem I ran into with this method was task tray entries. Some programs won't work if their task tray entry fails. If the software you want to run wants to put an icon in the task tray you can try enabling "Allow service to interact with the desktop" on the "Log On" tab of the Service properties. If that doesn't work you could also try disabling the task tray entry for the program.
  3. Launcher Service
    Camarade_Tux recommends Launcher Service. It is free and open source and looks very flexible and useful. This program has several unique features:
    • Start or stop a program based on network connectivity
    • External program can be run before or after execution
    • Delete *.tmp and *.pid files from the program's startup folder before execution
  4. WinServ
    QUOTE
    WinServ is a utility that can create an NT service that runs any application. When the application exits, the service becomes stopped.
    I did not try this program but included it here since it is free, open source and looks useful.
  5. Non-free options
    There are quite a few shareware and payware options. I didn't try any of them but I hear that FireDaemon works well for a lot of people.
References
  • http://support.microsoft.com/kb/251192
  • http://support.microsoft.com/kb/q137890
  • http://www.tacktech.com/display.cfm?ttid=197
  • http://www.msfn.org/board/index.php?showtopic=72799
  • http://www.msfn.org/board/index.php?showtopic=40581
  • http://www.msfn.org/board/index.php?showtopic=62482
  • http://www.codeproject.com/system/serviceskeleton.asp
Go to the top of the page
 
+Quote Post
 
Start new topic
Replies
kitaec
post Oct 1 2006, 01:57 PM
Post #2


Newbie


Group: Members
Posts: 18
Joined: 12-May 06
Member No.: 96171
Country Flag


TAiN
Thank you. But doesn't sc.exe applies to .EXE files? And if there is a .SYS file (say - system driver)? And there are two .INF files with it which install and specify this .SYS as a service. But they don't make it to start like a service sad.gif

Vbscripts can't be used for some reason smile.gif
Go to the top of the page
 
+Quote Post
tain
post Jul 26 2007, 08:12 AM
Post #3


Cyber Ops
Group Icon

Group: Super Moderator
Posts: 3089
Joined: 24-September 05
From: Ft Meade, Maryland, USA
Member No.: 74319
OS: XP Pro x86
Country Flag


QUOTE (kitaec @ Oct 1 2006, 01:57 PM) *
But doesn't sc.exe applies to .EXE files?
Yes. What are you trying to do?

Just stumbled onto this page today:
Quick Start Multiple Services using Batch and Net
Nothing new, but demonstrates usage of the batch commands.
Go to the top of the page
 
+Quote Post

Posts in this topic


Google Frontpage Forums Unattended CD/DVD Guide

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 




Lo-Fi Version Time is now: 21st November 2009 - 06:17 PM
All trademarks mentioned on this page are the property of their respective owners
MSFN is not affiliated with Microsoft
Copyright © 2001-2009 msfn.org
Privacy Policy