最近部署了个java程序,是用批处理去启动jar允许的,结果发现了一个问题,由于部署的是公共的机器,别人访问的时候会一不小心把机器给关了,或者把程序给关闭了。
于是想到利用windows 服务来启动这个程序,google了下发现sc命令好用。
sc命令的详解可以参考baidu百科,不过好长~~~
http://baike.baidu.com/view/1367668.htm
C:/Documents and Settings/Administrator>sc help
*** Unrecognized Command ***
DESCRIPTION:
SC is a command line program used for communicating with the
NT Service Controller and services.
USAGE:
sc <server> [command] [service name] <option1> <option2>...
The option <server> has the form "//ServerName"
Further help on commands can be obtained by typing: "sc [command]"
Commands:
query-----------Queries the status for a service, or
enumerates the status for types of services.
queryex---------Queries the extended status for a service, or
enumerates the status for types of services.
start-----------Starts a service.
pause-----------Sends a PAUSE control request to a service.
interrogate-----Sends an INTERROGATE control request to a service.
continue--------Sends a CONTINUE control request to a service.
stop------------Sends a STOP request to a service.
config----------Changes the configuration of a service (persistant).
description-----Changes the description of a service.
failure---------Changes the actions taken by a service upon failure.
sidtype---------Changes the service SID type of a service.
qc--------------Queries the configuration information for a service.
qdescription----Queries the description for a service.
qfailure--------Queries the actions taken by a service upon failure.
qsidtype--------Queries the service SID type of a service.
delete----------Deletes a service (from the registry).
create----------Creates a service. (adds it to the registry).
control---------Sends a control to a service.
sdshow----------Displays a service's security descriptor.
sdset-----------Sets a service's security descriptor.
showsid---------Displays the service SID string corresponding to an a
bitrary name.
GetDisplayName--Gets the DisplayName for a service.
GetKeyName------Gets the ServiceKeyName for a service.
EnumDepend------Enumerates Service Dependencies.
The following commands don't require a service name:
sc <server> <command> <option>
boot------------(ok | bad) Indicates whether the last boot should
be saved as the last-known-good boot configuration
Lock------------Locks the Service Database
QueryLock-------Queries the LockStatus for the SCManager Database
EXAMPLE:
sc start MyService
Would you like to see help for the QUERY and QUERYEX commands? [ y | n ]: n
加入服务:
sc create ServiceName binPath= 路径 start= auto
如C:/Documents and Settings/Administrator>sc create LTService binPath= D:/ZYing/work/utomation/Delirables/Code/lt.bat
[SC] CreateService SUCCESS
此时创建的服务是需要手动启动的,如果需要自动启动加入 start= auto
创建完毕后可以在控制面包--》管理工具--》服务中看到你的服务
事情还没完,创建完服务后,启动,发现报错:
error1053 the service did not response to start or control
这个问题还在查,查到后更新