DOS调用BAT

DOS调用BAT,第1张

1.DOS下如何调用BAT文件、命令是什么?

在dos命令行提示符下,直接输入.bat文件" highlight="true">bat文件的名称,比如:test.bat,直接输入test或test.bat,如果当前路径与bat文件不在一个路径下,在加上bat文件的路径,比如:c:\test\test.bat。

2.DOS下生成BAT的命令是什么?

在dos命令行提示符下,输入edit,按回车,会打开文本编辑器edit,你可以直接将dos命令输入进去,然后保存为 文件名.bat即可。

或者,也可以用 copy con命令,其格式如下:COPY CON test.bat

这个命令就是把键盘输入保存到test.bat文件中,当你输入这个命令后,DOS将会等待你的输入,输入完成后按CTRL+Z保存。

小提示:COPY CON命令是把键盘输入拷贝一个地方(CON是MS-DOS预定义的标准输入设备,即键盘)。

请问你的arpbd.bat文件在什么位置呢?如果是文件的完整路径是“c:\arpbd.bat”的话,那么命令就是:

reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Run" /v "arpbd" /t REG_SZ /d "c:\arpbd.bat"

另外,如果你要添加的是文件自身的话,可以用变量“%0”来代替。例如:

reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Run" /v "arpbd" /t REG_SZ /d "%0"

附上reg add命令的帮助信息:

REG ADD KeyName [/v ValueName | /ve] [/t Type] [/s Separator] [/d Data] [/f]

KeyName [\\Machine\]FullKey

远程机器的机器名 - 忽略默认到当前机器。

远程机器上只有 HKLM 和 HKU。

FullKey ROOTKEY\SubKey

ROOTKEY [ HKLM | HKCU | HKCR | HKU | HKCC ]

SubKey 所选 ROOTKEY 下注册表项的完整名

/v 所选项之下要添加的值名

/ve 为注册表项添加空白值名<无名称>

/t RegKey 数据类型

[ REG_SZ| REG_MULTI_SZ | REG_DWORD_BIG_ENDIAN|

REG_DWORD | REG_BINARY| REG_DWORD_LITTLE_ENDIAN |

REG_NONE | REG_EXPAND_SZ ]

如果忽略,则采用 REG_SZ

/s 指定一个在 REG_MULTI_SZ 数据字符串中

用作分隔符的字符

如果忽略,则将 "\0" 用作分隔符

/d 要分配给添加的注册表 ValueName 的数据

/f 不用提示就强行改写现有注册表项

例如:

REG ADD \\ABC\HKLM\Software\MyCo

添加远程机器 ABC 上的一个注册表项 HKLM\Software\MyCo

REG ADD HKLM\Software\MyCo /v Data /t REG_BINARY /d fe340ead

添加一个值(名称: Data,类型: REG_BINARY,数据: fe340ead)

REG ADD HKLM\Software\MyCo /v MRU /t REG_MULTI_SZ /d fax\0mail

添加一个值(名称: MRU,类型: REG_MUTLI_SZ,数据: fax\0mail\0\0)

REG ADD HKLM\Software\MyCo /v Path /t REG_EXPAND_SZ /d %%systemroot%%

添加一个值(名称: Path,类型: REG_EXPAND_SZ,数据: %systemroot%)

注意: 在扩充字符串中使用双百分比符号( %% )

首先下载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 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.重启系统后,在本地登录前,先用远程桌面登入,发现并未d出cmd程序

query user 检查本地还未登录

sc query cmdservice 发现服务已运行

tasklist 显示cmd.exe所有者为system

4.直接本地登录,立即d出cmd.exe的界面

结论:

1. 普通程序以服务启动时,程序属system所有

2.以服务启动时,指定type= interact以便于与用户交互,但这个交互只限于本地登录的帐户


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11956204.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-19
下一篇 2023-05-19

发表评论

登录后才能评论

评论列表(0条)

保存