Reputation: 2257
I am trying to create a service on Windows using my own executable. When I try to start the service, I get the error message:
"The service on Local Computer started and then stopped. Some services stop automatically if they have no work to do..."
The exe should always be doing work because it is constantly running a timer that checks the time and makes database backups at certain points during the day. I have tested the executable on its own (not as a service) and it works fine.
I created the service using a batch file and INSTSRV.EXE and SRVANY.EXE. The batch file looks like this:
start /d "C:\<exe directory>" INSTSRV.EXE <service name> "C:\<exe
directory>\SRVANY.EXE"
The server name now shows up in my list of services on my computer. I also edited the registry to make sure everything was in order. Here is what my regedit entry looks like:
Service key
DisplayName REG_SZ <service name>
ErrorControl REG_DWORD 0
ImagePath REG_EXPAND_SZ "C:\<exe directory>\SRVANY.EXE" <service name> C:\<exe directory>\SRVANY.EXE
ObjectName REG_SZ LocalSystem
Start REG_DWORD 2
Type REG_DWORD 16
Parameters key
AppDirectory REG_SZ E:\<exe directory>\
Application REG_SZ E:\<exe directory>\<exe file name>
I have used a similar batch file before to make a service from an executable, and I have compared the registry entries of that service with my own service's registry entries. They are pretty identical. I don't know why my service doesn't want to start.
Upvotes: 2
Views: 14941
Reputation: 2257
I incorrectly named the executable in the Application key path. Woops! Sorry for the trouble guys.
Upvotes: 1
Reputation: 2433
It looks like your ImagePath value is incorrect. It should just contain the full path to the Srvany executable, and no more.
Indeed, when I have Srvany and Instsrv in "C:\Apps\Win2K3RK" and run:
C:\Apps\Win2K3RK\Instsrv.exe MyService C:\Apps\Win2K3RK\srvany.exe
the registry key created looks like this:
Upvotes: 4