Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
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.
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to email@example.com. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
and provide relevant evidence. A staff member will contact you within 5 working days.