Atitit. Java & #160; exe & #160; bat & #160; & #160; run as a windows system service, atitit. javabat

Source: Internet
Author: User

Atitit. Java exe bat runs as a windows system service, atitit. javabat

Atitit. Java exe bat runs as a windows system service


1. Use sccommand to configure srvany.exe (good, recommended) + net start1

1.1. First create a java running bat1

1.2. Configure srvany for serv wrapper1

1.3. Use SC to create/del Service 1

1.4. start/stop service SC \ start ServicenameAti22

2. 1. There are two ways to modify the registry ...... There is also a useful command: SC delete + service name 3

3. ava Service Wrapper (jsw) 3

4. assumervice 4

5. 4

6. Refer to 4


1. Use sccommand to configure srvany.exe (good, recommended) + net start


1.1. First create a java running bat1.2. configure srvany for serv wrapper

[HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ services \ ServicenameAti2 \ Parameters]

"Application" = "\" D:/workspace space/AtiPlatf/makefile. bat \""


Srvany can be used to run any EXE program as a Windows service. That is to say, srvany is only the service shell of its registration program.

The start stop command of the service can be received. If bat exe is directly used, which horses implement the serv interface cannot be rootv serv ..

Author: nickname: old wow's paw (full name: Attilax Akbar Al Rapanui Attila Akba Arla Panui) Name: AI long, EMAIL:

Reprinted please indicate Source:


1.3. Use SC to create/del services

First, enter the command line (start --> Run -- Enter CMD) and directly enter SC to view help about the command.

To delete a system service, you can use SC delete [service name]. For example, to delete messager, enter SC DELETE MESSAGER.
SC uses the following syntax:
1. SC "Servername" command Servicename [Optionname = Optionvalue]

SC [command]


Option: the format of option <server> is "\ ServerName"

Note: The option name includes the equal sign.

A space is required between equal signs and values.


C: \ Users \ Administrator> SC \ create ServicenameAti binPath = "D: \ work

Ace space \ AtiPlatf \ makefile. bat "start = auto Displayname =" DisplaynameAti"

[SC] CreateService successful

SC \ delete ServicenameAti

SC \ start ServicenameAti2



Displayname is displayed on the service Manager ..


1.4. start/stop service SC \ start ServicenameAti2


C: \ Users \ Administrator> SC \ start ServicenameAti2


SERVICE_NAME: ServicenameAti2




WIN32_EXIT_CODE: 0 (0x0)



WAIT_HINT: 0x7d0

PID: 10308



Net start ServicenameAti2

Net stop ServicenameAti2



But this cannot stop whern serv stop... maybe check service start state timer... if stop then exit



2. 1. There are two ways to modify the registry ...... There is also a useful command: SC delete + service name

Run "register regedit.exe" at the beginning of "login", open "Registry Editor", and expand the branch "HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services". The service items installed on the local machine are displayed in the right pane.
If you want to create a service, you only need to click "Edit> New> item" and name it, for example, "test". Then, right-click the item, select "New> string value" or "New> DWORD Value. To add a service project, you must add the following key values:

"DisplayName", string value, corresponding service name;
"Description", string value, corresponding to the service Description;
"ImagePath", string value, the path to which the service program should be located;
"ObjectName", string value, value: "LocalSystem", indicates local login;
"ErrorControl", DWORD value, value: "1 ";
"Start", DWORD value, value 2 indicates automatic operation, value 3 indicates manual operation, value 4 indicates prohibited;
"Type", DWORD Value, the application corresponds to 10, and the other corresponds to 20.
Create an "Enum" item under "test. Follow these steps to add the QQ program as a service. After restarting the computer, open the "service" window and you will see the QQ service you just added.
To delete a service, you only need to delete the key value in the Registry. In this example, You need to delete the QQ service and directly Delete the "HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ test" branch.


3. ava Service Wrapper (jsw)

Open the JBOSS and Tomcat release packages and find that they all use an Open source -- Java Service Wrapper. Using Java Service Wrapper can easily solve our needs and make our Service programs a Win32 system Service.


JSW can be used in three ways:


Use WrapperSimpleApp class to start the application. This is the simplest and recommended method to use JSW. But there is a problem with using this method, because JSW directly uses System. exit () to exit JVM. This is the case if the user directly presses ctrl-c to exit the program during the application program running. If the application needs to run clean up before exiting, You need to register the shutdown hook, or do not use this method. Example of JBoss configuration in this way (Win32, Linux/UNIX ).



The second method is to use WrapperStartStopApp class. This method is used for applications such as Tomcat (that is, applications started in one class but ended with another class ). Generally, such applications open a server socket at startup to wait for the connection that requires the program to end. When the request to end is received, the "end" class will be executed. JSW directly executes this "end" class when it receives the requirement to stop running. Example of how to configure Tomcat in this way (Win32, Linux/UNIX ).



The third method is the most complex and flexible, and the only method that requires programming. In this way, you need to write a class that implements the WrapperListener interface. Some functions are exclusive to this method, such as directly receiving and responding to system control events (such as startup and termination) in the program ). But this also increases the complexity of the program. If you do not need these features, it is easier to use the first method. Example of configuration in this way.


Disadvantage: It seems that you can only set the java program. You can also set the bat file. But it may be troublesome.

4. assumervice



. Reference


Java program runs as a service in windows.-Happy!-blog. htm

Create a custom service item for system services on Windows.

Atitit. Add win System Service bat batch processing program service method summary instsrv srvany java linux-attilax column-blog channel-CSDN.NET.htm

Paip. Summary of registering a java program as a service for LINUX. -Attilax column-blog channel-CSDN.NET.htm

Related Article

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.