Solved

Convert exe to service

Posted on 2013-05-22
6
828 Views
Last Modified: 2013-05-22
Hey Experts.  I have a program (in-house app) that needs to run continuously so I decided I would take the exe and make it into a service.  When I run the command, I get the message [SC] CreateService Success but when I try to launch the service, it errors out with the standard "Could not start the program service on local computer / error 1053".  

Here is the command I am using:
sc create Program binPath= "c:\program name.exe" DisplayName= "Chat Program" start= auto

Open in new window


Not sure what I'm missing here but it would be great to get this working.  I'm running this when the process is not already running, logged in with local admin rights and this is a Windows 2003 server.  Thanks for your help!
0
Comment
Question by:samiam41
  • 4
  • 2
6 Comments
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 39188399
sc.exe just creates an entry for the Service Manager; it does not enable a regular program to behave like a service.
So you either need to redesign your app so that it works like an service, or (maybe easier) use a "service wrapper" like SrvAny.exe (in the W2k3 Resource Kit, http://www.microsoft.com/en-us/download/details.aspx?id=17657) or this one (easier to handle and more options than SrvAny):
NSSM - the Non-Sucking Service Manager
http://nssm.cc/
0
 
LVL 9

Author Comment

by:samiam41
ID: 39188427
oBdA!  Great to see you again.  As I was reading your explanation, it clicked.  Checking out the two options you listed.
0
 
LVL 9

Author Comment

by:samiam41
ID: 39188607
Tried each suggestion you made in your reply and each yielded the same error (could not start service.....)

After creating the service, do I need to restart the server?  I didn't think so.
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 9

Author Comment

by:samiam41
ID: 39188662
Ok.  I tried the NSSM again but did so after making a couple of changes.  First, the exe has a space between the name [Chat Program.exe].  So I made a copy of the program and renamed it ChatProgram.exe.  Then I created it again using NSSM, after making sure all references to that service were deleted out, with a different service name than was used previous.  Lastly, I didn't use the [browse] option when NSSM opened up.  I simply typed in the path of the exe.  I noticed when I would use the browse option, the path I selected wasn't displayed but actually showed the exe of the NSSM path!  

Whatever it was worked as the service runs like it should.  Any suggestions on what could have been the issue?  Was the space in the exe causing a problem?  Thanks for your help.  I'll award points once I hear back.
0
 
LVL 84

Expert Comment

by:oBdA
ID: 39188731
Sorry, I have no idea what went wrong the first time. Might have been leftovers from the sc.exe attempts.
Just checked with the current version of nssm; I put nssm.exe and a batch file named "Batch Service.cmd" (including the space) into the same folder, ran nssm.exe install "Batch Service" from an elevated command prompt, used the Browse button to find the batch file, and started the service. The batch file is happily writing its time stamps.
@echo off
setlocal
set LogFile=%~dpn0.log
:Loop
>"%LogFile%" echo %Date% %Time% ---- %*
sleep.exe 60
goto Loop

Open in new window

0
 
LVL 9

Author Closing Comment

by:samiam41
ID: 39188740
Thanks as always for your time and attention to this question!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction People like FTP.  It's a solid, stable, robust protocol for quickly transferring files between two hosts using TCP/IP.  In most cases it's much faster than SMB or CIFS, and certainly much easier to set up between organizations.  This…
Preface There are many applications where some computing systems need have their system clocks running synchronized within a small margin and eventually need to be in sync with the global time. There are different solutions for this, i.e. the W3…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question