Registering a batch file as a service
Two days ago completed the Java program to register as a win service, now I have a Java project lifting contains the startup script Startagent.bat. The effect I want to achieve is to automatically invoke the Startagent.bat script when the system starts, and then start searching for relevant information online.
1, first by the senior prompts can use System command SC implementation
SC Create service name binpath=. bat file Path Start=auto
(note = A space is followed by quotation marks if the file path contains spaces)
The specific parameters can be viewed using SC/?
The installation was quite smooth, the newly installed service appeared in the management/service, but the error occurred at startup:
"Unable to start the Server service on the local computer, error 5: Access Denied"
Use when deleting a service
SC Delete Service Name
Error: "XXX service marked for deletion"
Reinstall the error:
"Error 1053: Service does not respond to start or control requests in a timely manner"
Try not fruit, and every netizen said this way is not workable, want to start as a service. The bat file must conform to the specific format specified on MSDN.
--------------Try a new scheme--------------
To register Windows service methods with Instsrv.exe/srvany.exe:
1. Registration Service: X:/XXX/INSTSRV Service name X:/xxx/srvany.exe (note to use "/")
--------Register Srvany.exe as a system service
2. Regedit Open the Registry
3. Enter hkey_local_machine/system/currentcontrolset/services/service Name
4. Right Key-new-item fill in Parameters
5. Open parameters, right Key-new-string value application
6. Double-click Application to fill in the absolute path of the application, such as: E:/jboss-4.0.5.ga/bin/starteos.bat
7. Right Key-New-string value appdirectory
8. Double-click Appdirectory to fill in the application's working directory, such as: E:/jboss-4.0.5.ga/bin
-----------is defined in the registry by Srvany.exe startup. EXE application
9. Start the service.
(Note: 7 and 8 essential)
See the defined service in Windows Service Manager ...
The problem was solved, but there were strange 2 scenes:
A, startup in service, shutdown service appears to be invalid, only restart will take effect
B, the configuration file is restored every time? (estimated to be from one of their own minor modifications, to be identified ...)
Finally through reconstruction to solve the B problem, why? My Changes?... ...
Delete a custom service?
If you want to uninstall a local service, you can enter the following command from the command line
SC Delete ServiceName
or modify the registry directly
Deletes the corresponding key value in the hkey_local_machine/system/currentcontrolset/services.