微软官方MSDN原版Win10系统下载

现在位置: 首页  > 系统教程  > 系统帮助

.bat文件如何生成

时间:2024-05-19 03:43:12   

大家好,今天Win10系统之家小编给大家分享「.bat文件如何生成」的知识,如果能碰巧解决你现在面临的问题,记得收藏本站或分享给你的好友们哟~,现在开始吧!

图片生成PDF文件 - 轻松转换图片为PDF格式系列软件最新版本下载

1..bat文件如何生成windows服务


  首先下载java service wrapper工具
步骤:
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 Wrappers 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 | 
#你的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以便于与用户交互,但这个交互只限于本地登录的帐户

2.bat批量处理怎样用,怎样生成


  常见批处理案例简单的说,批处理的作用就是自动的连续执行多条命令。
这里先讲一个最简单的应用:在启动wps软件时,每次都必须执行( >前面内容表示DOS提示符): 
C:>cd wps 
C:WPS>spdos
C:WPS>py 
C:WPS>wbx 
C:WPS>wps 
如果每次用WPS之前都这样执行一遍,您是不是觉得很麻烦呢?
好了,用批处理,就可以实现将这些麻烦的操作简单化,首先我们编写一个runwps.bat批处理文件,内容如下:
@echo off
c:
cdwps
spdos
py
wbx
wps
cd
以后,每次进入wps,只需要运行runwps这个批处理文件即可。
批处理 - 命令
echo、@、call、pause、rem 是批处理文件最常用的几个命令。 
echo 表示显示此命令后的字符 
echo off 表示在此语句后所有运行的命令都不显示命令行本身 
@与echo off相象,但它是加在每个命令行的最前面,表示运行时不显示这一行的命令行(只能影响当前行)。 
call 调用另一个批处理文件(如果不用call而直接调用别的批处理文件,那么执行完那个批处理文件后将无法返回当前文件并执行当前文件的后续命令)。 
pause 运行此句会暂停批处理的执行并在屏幕上显示Press any key to continue...的提示,等待用户按任意键后继续 
rem 表示此命令后的字符为解释行(注释),不执行,只是给自己今后参考用的(相当于程序中的注释)。
批处理 - 特殊命令
选择批处理if goto choice for是批处理文件中比较高级的命令。
一、if 是条件语句,用来判断是否符合规定的条件,从而决定执行不同的命令。 有三种格式: 
1、if [not] "参数" == "字符串" 待执行的命令 
参数如果等于(not表示不等,下同)指定的字符串,则条件成立,运行命令,否则运行下一句。
例:if "%1"=="a" format a:
2、if [not] exist [路径]文件名 待执行的命令 
如果有指定的文件,则条件成立,运行命令,否则运行下一句。
如: if exist c:config.sys type c:config.sys 
表示如果存在c:config.sys文件,则显示它的内容。
3、if errorlevel 数字 待执行的命令 
很多DOS程序在运行结束后会返回一个数字值用来表示程序运行的结果(或者状态),通过if errorlevel命令可以判断程序的返回值,根据不同的返回值来决定执行不同的命令(返回值必须按照从大到小的顺序排列)。如果返回值等于指定的数字,则条件成立,运行命令,否则运行下一句。
如if errorlevel 2 goto x2
二、goto 批处理文件运行到这里将跳到goto所指定的标号(标号即label,标号用:后跟标准字符串来定义)处,goto语句一般与if 配合使用,根据不同的条件来执行不同的命令组。 
如:
goto end 
:end 
echo this is the end 
标号用“:字符串”来定义,标号所在行不被执行。 
三、choice 使用此命令可以让用户输入一个字符(用于选择),从而根据用户的选择返回不同的errorlevel,然后于if errorlevel配合,根据用户的选择运行不同的命令。
注意:choice命令为DOS或者Windows系统提供的外部命令,不同版本的choice命令语法会稍有不同,请用choice /?查看用法。
choice的命令语法(该语法为Windows 2003中choice命令的语法,其它版本的choice的命令语法与此大同小异):
CHOICE [/C choices] [/N] [/CS] [/T timeout /D choice] [/M text]
描述:
该工具允许用户从选择列表选择一个项目并返回所选项目的索引。
四、for循环命令,只要条件符合,它将多次执行同一命令。 
语法:
对一组文件中的每一个文件执行某个特定命令。
FOR %%variable IN (set) DO command [command-parameters]
 %%variable 指定一个单一字母可替换的参数。
 (set) 指定一个或一组文件。可以使用通配符。
 command 指定对每个文件执行的命令。
 command-parameters
 为特定命令指定参数或命令行开关。
例如一个批处理文件中有一行: 
for %%c in (*.bat *.txt) do type %%c 
则该命令行会显示当前目录下所有以bat和txt为扩展名的文件的内容。
批处理 - 参数
批处理过程批处理文件还可以像C语言的函数一样使用参数(相当于DOS命令的命令行参数),这需要用到一个参数表示符“%”。 
%[1-9]表示参数,参数是指在运行批处理文件时在文件名后加的以空格(或者Tab)分隔的字符串。变量可以从%0到%9,%0表示批处理命令本身,其它参数字符串用%1到%9顺序表示。 
参数列表
 /C choices 指定要创建的选项列表。默认列表是 "YN"。
 /N 在提示符中隐藏选项列表。提示前面的消息得到显示,
 选项依旧处于启用状态。
 /CS 允许选择分大小写的选项。在默认情况下,这个工具
 是不分大小写的。
 /T timeout 做出默认选择之前,暂停的秒数。可接受的值是从 0
 到 9999。如果指定了 0,就不会有暂停,默认选项
 会得到选择。
 /D choice 在 nnnn 秒之后指定默认选项。字符必须在用 /C 选
 项指定的一组选择中; 同时,必须用 /T 指定 nnnn。
 /M text 指定提示之前要显示的消息。如果没有指定,工具只
 显示提示。
 /? 显示帮助消息。

以上就是关于「.bat文件如何生成」的全部内容,本文讲解到这里啦,希望对大家有所帮助。如果你还想了解更多这方面的信息,记得收藏关注本站~

【②本文来*源Win10系统之家,不得自行转载,违者必追究!】

相关文章

  • .bat文件如何生成

    .bat文件如何生成

    1..bat文件如何生成windows服务首先下载javaservicewrapper工具步骤:1、解压缩javaservicewrapper包,假设目录为:wrapper_home2、建立一个目录比如:D盘server文件夹里面建立bin、conf、logs、lib文件夹。3、将wrapper_home/...
  • EasyBoot制作启动盘不支持大于4G的文件如何解决

    EasyBoot制作启动盘不支持大于4G的文件如何解决


      有不少用户使用EasyBoot(EZBoot)制作系统启动盘,发现EZboot不能完美支持超过4G的单个文件。当ISO镜像中有大于4G的单个文件时,启动时会出现如下界面:
      面对这种情况除了尽可能减小GHO和WIM文件的体积,难道没有其它方法可以解决了吗?对于GHO我们都知道可以用Ghostexp设置一下分卷大小分割一下就可以了,点视图——选项,分割成两个文件,再文件——编...
  • win7系统如何安全清理hosts文件

    win7系统如何安全清理hosts文件

    1.win7系统host文件打开是空白的怎么办?win7系统host文件打开为空有两种解决方法,首先找到hosts文件:方法一:通过路径查找:c:\windows\system32\drivers\etc方法二:通过运行(快捷键Win+R)输入“路径”查找。进入文件夹...
  • 如何从pdf文件转换成word文档

    如何从pdf文件转换成word文档

    1.怎样把PDF格式文档转换成WORD文档在实际工作中,我们可能经常需要从PDF文档中获得相关的内容,在没有安装AdobeAcrobat的情况下,可以利用MicrosoftOffice2007套件中的MicrosoftOfficeDocumentImaging组件实现PDF→DOC...