Registering a batch file as a service

Source: Internet
Author: User
Tags jboss

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--------------

Using Instsrv.exe/srvany.exe

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:/

7. Right Key-New-string value appdirectory

8. Double-click Appdirectory to fill in the application's working directory, such as: E:/

-----------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.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.