I have a Java program which needs to be a startup program that runs as administrator. It seems that cannot be done without making it a service. I have tried using HKLM\SYSTEM\CurrentControlSet\Services\Services\MyService
. I tried something similar to what Google Updater uses (they use ...\Services\gupdate
). The process does not start (or at least it stops right away, which I cannot tell for sure.
I think it is something wrong with how I am using the registry because the service does not show up in msconfig.exe
under the Services tab. Also it doe not show up in the Control Panel "View local services" (Windows 7, found in the Start Menu search for "services")
I tried a much simpler approach found here. I create a .reg
file with these contents.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MyService]
"Description"="My Service starts the Special Process."
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MyService\Parameters]
"Application"="C:\\Test\\MyProcess.cmd"
I am willing to consider an alternative command-line alternative if necessary, but I like the registry approach because if I tell my installer to add certain registry items, it will automatically remove those items on uninstall.
Is there any reason that above .reg
file would not add an item to msconfig
that is named "MyService"?
The program which I wrote is written in Java. It does not have a GUI interface.
You can't create a service by manipulating the registry. Nor can you run an arbitrary application as a service.
To run an arbitrary program from within a service, use the srvany.exe service available in the Windows Server 2003 resource kit. See KB137890 for instructions. If you want to write your own service, see this.
To create a service you can use the sc command line tool, or the instsrv.exe tool from the Windows Server 2003 resource kit. Or use the CreateService Win32 API function.