⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 批处理讲解.htm

📁 DOS和批处理技术 这些是我长期学习积累下来的总共有47个文件
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0035)http://hooke.javaeye.com/blog/45843 -->
<HTML dir=ltr xml:lang="zh-CN" 
xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>dos 批处理 命令大全 - hooke - JavaEye技术网站</TITLE>
<META http-equiv=Content-Type content="text/html; charset=UTF-8">
<META 
content="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1.Echo 命令  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 打开回显或关闭请求回显功能,或显示消息。如果没有任何参数,echo 命令将显示当前回显设置。  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 语法  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo [{on|off}] [message]  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sample篅echo off / echo hello world  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在实际应用中我们会把这条命令和重定向符号(也称为管道符号,一般用> &amp;g ..." 
name=description>
<META content="  dos 批处理 命令大全" name=keywords><LINK href="/images/favicon.ico" 
type=image/x-icon rel="shortcut icon"><LINK title=hooke href="/rss" 
type=application/rss+xml rel=alternate><LINK media=screen 
href="dos 批处理 命令大全 - hooke - JavaEye技术网站.files/blog.css" type=text/css 
rel=stylesheet><LINK media=screen 
href="dos 批处理 命令大全 - hooke - JavaEye技术网站.files/blue.css" type=text/css 
rel=stylesheet>
<SCRIPT src="dos 批处理 命令大全 - hooke - JavaEye技术网站.files/application.js" 
type=text/javascript></SCRIPT>
<LINK media=screen 
href="dos 批处理 命令大全 - hooke - JavaEye技术网站.files/SyntaxHighlighter.css" 
type=text/css rel=stylesheet>
<SCRIPT src="dos 批处理 命令大全 - hooke - JavaEye技术网站.files/shCoreCommon.js" 
type=text/javascript></SCRIPT>

<STYLE>DIV#main {
	BORDER-TOP-WIDTH: 0px; PADDING-RIGHT: 0px; PADDING-LEFT: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; PADDING-BOTTOM: 0px; WIDTH: 740px; PADDING-TOP: 0px; BACKGROUND-COLOR: transparent; BORDER-RIGHT-WIDTH: 0px
}
</STYLE>
<LINK media=screen href="dos 批处理 命令大全 - hooke - JavaEye技术网站.files/ui.css" 
type=text/css rel=stylesheet>
<SCRIPT src="dos 批处理 命令大全 - hooke - JavaEye技术网站.files/compress.js" 
type=text/javascript></SCRIPT>

<META content="MSHTML 6.00.2900.5726" name=GENERATOR></HEAD>
<BODY>
<DIV id=header>
<DIV id=blog_site_nav><A class=homepage href="http://www.javaeye.com/">首页</A> <A 
href="http://www.javaeye.com/news">新闻</A> <A 
href="http://www.javaeye.com/forums">论坛</A> <A 
href="http://www.javaeye.com/blogs">博客</A> <A 
href="http://job.javaeye.com/">招聘</A> <A id=msna onclick="return false;" 
href="http://hooke.javaeye.com/blog/45843#"><U>更多</U> <SMALL>▼</SMALL></A> 
<DIV class=quick_menu style="DISPLAY: none"><A 
href="http://www.javaeye.com/ask">问答</A> <A 
href="http://www.javaeye.com/wiki">知识库</A> <A 
href="http://www.javaeye.com/groups">圈子</A> <A 
href="http://www.javaeye.com/search">搜索</A> </DIV></DIV>
<DIV id=user_nav><A class=welcome title=登录 
href="http://hooke.javaeye.com/login">您还没有登录 !</A> <A 
href="http://www.javaeye.com/all">全站动态</A> <A 
href="http://hooke.javaeye.com/login">登录</A> <A class=nobg 
href="http://hooke.javaeye.com/signup">注册</A> </DIV></DIV>
<DIV id=page>
<DIV class=clearfix id=branding>
<DIV id=blog_name>
<H1><A href="http://hooke.javaeye.com/">hooke</A></H1></DIV>
<DIV id=blog_preview></DIV>
<DIV id=blog_domain>永久域名 <A 
href="http://hooke.javaeye.com/">http://hooke.javaeye.com/</A></DIV></DIV>
<DIV class=clearfix id=content>
<DIV id=main>
<DIV class=blog_main>
<DIV id=blog_nav>
<DIV id=pre_next><A class=next 
href="http://hooke.javaeye.com/blog/48347">SpringAop</A> </DIV></DIV>
<DIV class=blog_title>
<DIV class=date><SPAN class=year>2007</SPAN><SPAN class=sep_year>-</SPAN><SPAN 
class=month>01</SPAN><SPAN class=sep_month>-</SPAN><SPAN 
class=day>10</SPAN></DIV>
<H3 class="" title=""><A href="http://hooke.javaeye.com/blog/45843">dos 批处理 
命令大全</A></H3></DIV>
<DIV class=blog_content>
<P><FONT size=+0>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1.Echo 命令 </FONT></P>
<P><FONT size=+0>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
打开回显或关闭请求回显功能,或显示消息。如果没有任何参数,echo 命令将显示当前回显设置。 </FONT></P>
<P><FONT size=+0>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 语法 </FONT></P>
<P><FONT size=+0>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo [{on|off}] [message] 
</FONT></P>
<P><FONT size=+0>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sample篅echo off / echo hello 
world </FONT></P>
<P><FONT size=+0>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
在实际应用中我们会把这条命令和重定向符号(也称为管道符号,一般用&gt; &gt;&gt; 
^)结合来实现输入一些命令到特定格式的文件中.这将在以后的例子中体现出来。&nbsp;</FONT></P><FONT size=+0>
<P><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2.@ 命令 </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
表示不显示@后面的命令,在入侵过程中(例如使用批处理来格式化敌人的硬盘)自然不能让对方看到你使用的命令啦。 </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sample:@echo off </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @echo Now initializing the program,please wait 
a minite... </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @format X: /q/u/autoset (format 
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
这个命令是不可以使用/y这个参数的,可喜的是微软留了个autoset这个参数给我们,效果和/y是一样的。) </P>
<P>&nbsp;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3.Goto 命令 </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 指定跳转到标签,找到标签后,程序将处理从下一行开始的命令。 </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 语法:goto label (label是参数,指定所要转向的批处理程序中的行。) </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sample: </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if {%1}=={} goto noparms </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if {%2}=={} goto 
noparms(如果这里的if、%1、%2你不明白的话,先跳过去,后面会有详细的解释。) </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @Rem check parameters if null show usage </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :noparms </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo Usage: monitor.bat ServerIP PortNumber 
</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; goto end </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
标签的名字可以随便起,但是最好是有意义的字母啦,字母前加个:用来表示这个字母是标签,goto命令就是根据这个:来寻找下一步跳到到那里。最好有一些说明这样你别人看起来才会理解你的意图啊。 
</P>
<P>&nbsp;</P>
<P><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4.Rem 命令 </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
注释命令,在C语言中相当与/*--------*/,它并不会被执行,只是起一个注释的作用,便于别人阅读和你自己日后修改。 </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Rem Message </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sample:@Rem Here is the description. </P>
<P>&nbsp;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5.Pause 命令 </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 运行 Pause 命令时,将显示下面的消息: </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Press any key to continue . . . </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sample: </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @echo off </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :begin </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; copy a:*.* d:\back </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo Please put a new disk into driver A </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pause </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; goto begin </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在这个例子中,驱动器 A 
中磁盘上的所有文件均复制到d:\back中。显示的注释提示您将另一张磁盘放入驱动器 A 时,pause 
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 命令会使程序挂起,以便您更换磁盘,然后按任意键继续处理。 </P>
<P>&nbsp;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 6.Call 命令 </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 从一个批处理程序调用另一个批处理程序,并且不终止父批处理程序。call 
命令接受用作调用目标的标签。如果在脚本或批处理文件外使用 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
Call,它将不会在命令行起作用。 </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 语法 </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call [[Drive:][Path] FileName 
[BatchParameters]] [:label [arguments]] </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 参数 </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Drive:}[Path] FileName </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 指定要调用的批处理程序的位置和名称。filename 参数必须具有 .bat 或 .cmd 
扩展名。 </P>
<P>&nbsp;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7.start 命令 </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 调用外部程序,所有的DOS命令和命令行程序都可以由start命令来调用。 </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 入侵常用参数: </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MIN 开始时窗口最小化 </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SEPARATE 在分开的空间内开始 16 位 Windows 程序 </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HIGH 在 HIGH 优先级类别开始应用程序 </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; REALTIME 在 REALTIME 优先级类别开始应用程序 </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WAIT 启动应用程序并等候它结束 </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; parameters 这些为传送到命令/程序的参数 </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 执行的应用程序是 32-位 GUI 应用程序时,CMD.EXE 
不等应用程序终止就返回命令提示。如果在命令脚本内执行,该新行为则不会发生。 </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 8.choice 命令 </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; choice <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
使用此命令可以让用户输入一个字符,从而运行不同的命令。使用时应该加/c:参数,c:后应写提示可输入的字符,之间无空格。它的返回码为1234…… </P>
<P>&nbsp;</P>
<P>&nbsp;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 如: choice /c:dme defrag,mem,end </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 将显示 </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; defrag,mem,end[D,M,E]? </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sample: </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sample.bat的内容如下: </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @echo off </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; choice /c:dme defrag,mem,end </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if errorlevel 3 goto defrag (应先判断数值最高的错误码) 
</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if errorlevel 2 goto mem </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if errotlevel 1 goto end </P>
<P>&nbsp;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :defrag </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c:\dos\defrag </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; goto end </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :mem </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mem </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; goto end </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :end </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo good bye </P>
<P>&nbsp;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 此文件运行后,将显示 defrag,mem,end[D,M,E]? 用户可选择d m e 
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
,然后if语句将作出判断,d表示执行标号为defrag的程序段,m表示执行标号为mem的程序段,e表示执行标号为end的程序段,每个程序段最后都以goto 
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end将程序跳到end标号处,然后程序将显示good bye,文件结束。 </P>
<P>&nbsp;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 9.If 命令 </P>
<P>&nbsp;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if 表示将判断是否符合规定的条件,从而决定执行不同的命令。 有三种格式: </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1、if "参数" == "字符串" 待执行的命令 </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 参数如果等于指定的字符串,则条件成立,运行命令,否则运行下一句。(注意是两个等号) </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 如if "%1"=="a" format a: </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if {%1}=={} goto noparms </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if {%2}=={} goto noparms </P>
<P>&nbsp;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2、if exist 文件名 待执行的命令 </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 如果有指定的文件,则条件成立,运行命令,否则运行下一句。 </P>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -