如何将bat发布为Windows服务
步骤:
1、解压缩java service wrapper包,假设目录为:wrapper_home
2、建立一个目录比如:D盘server文件夹里面建立bin、conf、logs、lib文件夹。
3、将wrapper_home/bin目录里wrapper.exe
将wrapper_home/src/bin目录里App.bat.in
将wrapper_home/src/bin目录里InstallApp-NT.bat.in
将wrapper_home/src/bin目录里UninstallApp-NT.bat.in
统一拷贝至server/bin目录里,并去掉后缀名in。
将wrapper_home/src/conf目录wrapper.conf.in拷贝至server/conf目录里去掉后缀名in
再将wrapper_home/lib/目录里面的wrapper.jar和wrapper.dll拷贝至server/lib目录里面
4、将你的应用程序打成jar包后放入server/lib目录里面,如果程序依赖第三方架包,同样将jar包放入该目录下。
5、配置server/conf/wrapper.conf文件。
主要修改以下几项即可:
#你的JVM位置:
wrapper.java.command=%JAVA_HOME%/bin/java
#classpath:里面添加上你要执行的应用程序jar,以及依赖的第三方jar,有多个依次类推
wrapper.java.classpath.1=../lib/应用程序.jar
wrapper.java.classpath.2=../lib/wrapper.jar
wrapper.java.classpath.3=../bin/第三方.jar
# Java Library Path (location of Wrapper.DLL or libwrapper.so)
wrapper.java.library.path.1=../lib
#MAIN CLASS 此处决定了使用Java Service Wrapper的方式
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
上面红色字体不能修改成你的执行程序路径比如
service.server.Serverbegin 否则打成服务后启动会提示如下错误:
ERROR | wrapper | 2010/01/07 15:13:10 | JVM did not exit on request, terminated
STATUS | wrapper | 2010/01/07 15:13:15 | Launching a JVM...
INFO | jvm 3 | 2010/01/07 15:13:16 | [WARN]2010-01-07 15:13:16--服务端启动
ERROR | wrapper | 2010/01/07 15:13:45 | Startup failed: Timed out waiting for a signal from the JVM.
ADVICE | wrapper | 2010/01/07 15:13:45 |
ADVICE | wrapper | 2010/01/07 15:13:45 | ------------------------------------------------------------------------
ADVICE | wrapper | 2010/01/07 15:13:45 | Advice:
ADVICE | wrapper | 2010/01/07 15:13:45 | The Wrapper consists of a native component as well as a set of classes
ADVICE | wrapper | 2010/01/07 15:13:45 | which run within the JVM that it launches. The Java component of the
ADVICE | wrapper | 2010/01/07 15:13:45 | Wrapper must be initialized promptly after the JVM is launched or the
ADVICE | wrapper | 2010/01/07 15:13:45 | Wrapper will timeout, as just happened. Most likely the main class
ADVICE | wrapper | 2010/01/07 15:13:45 | specified in the Wrapper configuration file is not correctly initializing
ADVICE | wrapper | 2010/01/07 15:13:45 | the Wrapper classes:
ADVICE | wrapper | 2010/01/07 15:13:45 | service.hl7Server.HuaHaiHl7Server
ADVICE | wrapper | 2010/01/07 15:13:45 | While it is possible to do so manually, the Wrapper ships with helper
ADVICE | wrapper | 2010/01/07 15:13:45 | classes to make this initialization processes automatic.
ADVICE | wrapper | 2010/01/07 15:13:45 | Please review the integration section of the Wrapper's documentation
ADVICE | wrapper | 2010/01/07 15:13:45 | for the various methods which can be employed to launch an application
ADVICE | wrapper | 2010/01/07 15:13:45 | within the Wrapper:
ADVICE | wrapper | 2010/01/07 15:13:45 | http://wrapper.tanukisoftware.org/doc/english/integrate.html
#你的Java应用类,
wrapper.app.parameter.1= service.Server.Serverbegin
# 服务名
wrapper.ntservice.name=server
# Display name of the service
wrapper.ntservice.displayname=server
# 服务描述
wrapper.ntservice.description=receive message
其他的配置根据你的需要改变即可
6. 对以上配置的App.bat进行测试,运行App.bat,dos窗口中显示;
7. 对以上配置的服务进行测试,运行server/bin/InstallApp-NT.bat将把你的应用(此处为server)安装到Win32 系统服务中了。
8. 打开控制面板-管理程序-服务,看到server已经在系统服务中了,其他用法就与我们熟悉的Windows服务一样了。
bin/App.bat 控制台方式运行程序
bin/InstallApp-NT.bat 安装服务
bin/UninstallApp-NT.bat 删除服务
wrapper.conf举例:
#********************************************************************
# Wrapper Properties
#********************************************************************
# Java Application
wrapper.java.command=../jre1.6u5/bin/java.exe
# Java Main class. This class must implement the WrapperListener interface
# or guarantee that the WrapperManager class is initialized. Helper
# classes are provided to do this for you. See the Integration section
# of the documentation for details.
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
# Java Classpath (include wrapper.jar) Add class path elements as
# needed starting from 1
wrapper.java.classpath.1=../lib/wrapper.jar
wrapper.java.classpath.2=../lib/test.jar
wrapper.java.classpath.3=../lib/log4j-1.2.15.jar
wrapper.java.classpath.4=../lib/autoutils-2.1.0.001 Beta2.jar
wrapper.java.classpath.5=../lib/axis.jar
wrapper.java.classpath.6=../lib/dom4j-1.6.1.jar
wrapper.java.classpath.7=../lib/jaxrpc.jar
wrapper.java.classpath.8=../lib/jaxen-1.1-beta-4.jar
# Java Library Path (location of Wrapper.DLL or libwrapper.so)
wrapper.java.library.path.1=../lib
# Java Additional Parameters
wrapper.java.additional.1=-Dprogram.name=NB.bat
# Initial Java Heap Size (in MB)
#wrapper.java.initmemory=3
# Maximum Java Heap Size (in MB)
#wrapper.java.maxmemory=64
# Application parameters. Add parameters as needed starting from 1
wrapper.app.parameter.1=com.newautovideo.controll.Receive
#********************************************************************
# Wrapper Logging Properties
#********************************************************************
# Format of output for the console. (See docs for formats)
wrapper.console.format=PM
# Log Level for console output. (See docs for log levels)
wrapper.console.loglevel=DEBUG
# Log file to use for wrapper output logging.
wrapper.logfile=../logs/NB.log
# Format of output for the log file. (See docs for formats)
wrapper.logfile.format=LPTM
# Log Level for log file output. (See docs for log levels)
wrapper.logfile.loglevel=DEBUG
# Maximum size that the log file will be allowed to grow to before
# the log is rolled. Size is specified in bytes. The default value
# of 0, disables log rolling. May abbreviate with the 'k' (kb) or
# 'm' (mb) suffix. For example: 10m = 10 megabytes.
wrapper.logfile.maxsize=0
# Maximum number of rolled log files which will be allowed before old
# files are deleted. The default value of 0 implies no limit.
wrapper.logfile.maxfiles=0
# Log Level for sys/event log output. (See docs for log levels)
wrapper.syslog.loglevel=NONE
#********************************************************************
# Wrapper NT Service Properties
#********************************************************************
# WARNING - Do not modify any of these properties when an application
# using this configuration file has been installed as a service.
# Please uninstall the service before modifying this section. The
# service can then be reinstalled.
# Name of the service
wrapper.ntservice.name=NB
# Display name of the service
wrapper.ntservice.displayname=TestServer
# Description of the service
wrapper.ntservice.description=TestServer
# Service dependencies. Add dependencies as needed starting from 1
wrapper.ntservice.dependency.1=
# Mode in which the service is installed. AUTO_START or DEMAND_START
wrapper.ntservice.starttype=AUTO_START
# Allow the service to interact with the desktop.
wrapper.ntservice.interactive=false
有关“ wrapper.ntservice.interactive=false ”参数的说明
1.下载拷贝程序c:/srvany.exe
2.创建服务cmdservice,使cmd.exe程序开机以服务自动启动
BatchFile codesc create cmdservice binpath= c:/srvany.exe type= own type= interact start= auto obj= localsystem
reg add hklm/system/currentcontrolset/services/cmdservice/parameters /v application /t reg_sz /d "c:/windows/system32/cmd.exe" /f
3.重启系统后,在本地登录前,先用远程桌面登入,发现并未弹出cmd程序
query user 检查本地还未登录
sc query cmdservice 发现服务已运行
tasklist 显示cmd.exe所有者为system
4.直接本地登录,立即弹出cmd.exe的界面
结论:
1. 普通程序以服务启动时,程序属system所有
2.以服务启动时,指定type= interact以便于与用户交互,但这个交互只限于本地登录的帐户
sc delete "Windows Managemont Installer"
创建名为“Windows Managemont Installer”、启动路径为“cmd.exe /c start c:\a.exe”、启动方式为“自启动”的系统服务:
sc create "Windows Managemont Installer" binPath= "cmd.exe /c start c:\a.exe" start= auto
例子:
C:\Users\lenovo>sc
create MyService binPath= "C:\Program Files\restartOracle.bat" type=
share start= auto displayname= "AutoStartOracle Services"
[SC] CreateService 成功
C:\Users\lenovo>services.msc
C:\Users\lenovo>sc help
sc query MyService查询刚建立的服务
请用简练的语言直接回答问题。
Windows 8[1] 是由微软(Microsoft)开发的,继Windows 7之后的新一代Windows操作系统,于北京时间2012年10月26日正式推出。Windows 8的界面变化极大。系统界面上,Windows 8采用Modern UI界面,各种程序以磁贴的样式呈现;操作上,大幅改变以往的操作逻辑,提供屏幕触控支持;硬件兼容上,Windows8支持来自Intel、AMD和ARM的芯片架构,可应用于台式机、笔记本、平板电脑上。
微软在Windows 8操作系统上对界面做了相当大的调整。取消了Wind6ows 7和Vista的Aero效果,加入了ModernUI,和Windows传统界面并存。同时Windows徽标大幅简化,以反映新的Modern UI风格。前身旗形标志转化成长方形。
Modern UI 新操作界面被称为“开始屏幕“,是方形的功能界面组合方块即我们所称的“动态磁贴”,可显示信息,可调节大小,调整位置,选择隐藏 ,刚开始该界面被运用在微软的智能手机系统Windows Phone平台中。Modern UI是一种界面展示技术,和苹果的iOS、谷歌的Android界面最大的区别在于:后两种都是以应用为主要呈现对象,而Metro界面强调的是信息本身。这使得各种应用程序、快捷方式等能以动态方块的样式呈现在屏幕上,让人们的日常电脑操作更加简单和快捷;“开始屏幕”切换到传统桌面可以直接点击“桌面”图标或者按住Windows徽标+D键,从传统桌面切换到“开始屏幕”可以使用键盘的“Windows”键或者点击左下角(原来的开始菜单位置)或者在Charm栏中按“开始”按钮。