1. bat
bat --->批处理文件
2.基本命令
echo 命令回显 ::或rem 注释语句
& 都执行 && 一个为false就结束 || 一个为true就结束
dir cd for if exist rd net 等基本命令
3.特例分析
(1)for循环
@echo off
set file1=myfile.txt
set file2="my files.txt"
set file3=mfile.txt
if not exist %file1% goto nono
for /f "eol=; tokens=2,3* delims=," %%i in (%file1%) do @echo %%i %%j %%k
echo great
if not exist %file2% goto nono
for /f "usebackq eol=; tokens=2,3* delims=," %%i in (%file2%) do @echo -%%i =%%j ===%%k===
echo best
if not exist %file3% goto nono
set alip=0
for /f "eol=; tokens=1 delims=," %%i in (%file3%) do (
set /a alip=alip+1
echo %%i
)
echo %alip%
pause
:nono
echo nofile
pause
以上为三个文件的for循环例子。先明确参数含义:
eol =; 表示忽略以;打头的行。
tokens=1表示取第一列 delims为分隔符。
usebackq 是当文件名中含有空格时使用的这时需要加引号。
(2) 基本命令示例
@echo this is my first lesson22
rem this is my first lesson111
@echo.
@echo N|rd /s d:\test
@echo N|rd /s d:\testsssssssss
@echo N|rd /s d:\test
@echo 111>test.txt
@echo .>>test.txt
@echo.>>test.txt
@echo 222>>test.txt
rem create test.txt ,add context
::this is a tip
@echo dir /p D:\
@echo this path is %cd%
@echo test some dir command bellow
@echo /a means all /o means order
::dir /p c:\ ---page
::dir /ah c:\ ---all hide file and folder
::dir /ad c:\ ---all folder d means directory
::dir /ad-h c:\ ---all folder but hide folder h means hide
::dir /on c:\ ----order by name
::dir /s /p c:\*.txt ---s means select
@echo test some rd command bello remove directory
::rd /s ---delete all
::rd /s 123 ---delete all files bellow directory 123
::del /q d:\test
@echo test copy
::copy d:\test.txt e:\ only file no directory
::xcopy /e test2 test1 copy things under test2 to test1
@echo color 3e
::ping /n 3 127.0.0.1>nul ping 3´ÎÑÓ³Ù6Ãë
::netstat -ano >test.txt
::type test.txt |find "8080" && echo "yes,you find it"
::del test.txt
::ping baidu.com >test.txt
rem type test.txt
echo start
rem if exist C:\progra~1\Tencent\AD\*.gif del C:\progra~1\Tencent\AD\*.gif
rem echo end
rem if exist c:\windows\temp\*.* del c:\windows\temp\*.*
pause
(3) start 相关文件启动
@echo IE start
set IEPATH="C:\Program Files\Internet Explorer\iexplore.exe"
set CODEPATH="D:\MyEclipse 8.5\"
set USERPATH=C:\Users\yimi\Desktop
start /d "%USERPATH%" test.txt
::start /WAIT /d %CODEPATH% myeclipse.exe
::D:\workplace\binary\com.sun.java.jdk.win32.x86_1.6.0.013\bin\java.exe "-Dcatalina.home=D:\Tomcat 6.0" "-Dcatalina.base=D:\Tomcat 6.0" "-Djava.endorsed.dirs=D:\Tomcat 6.0/common/endorsed" "-Djava.io.tmpdir=D:\Tomcat 6.0\temp" "-Djava.library.path=D:\workplace\binary\com.sun.java.jdk.win32.x86_1.6.0.013\bin;D:\Tomcat 6.0\bin" -Dsun.io.useCanonCaches=false -classpath "D:\Tomcat 6.0/bin/bootstrap.jar;D:\workplace\binary\com.sun.java.jdk.win32.x86_1.6.0.013/lib/tools.jar" org.apache.catalina.startup.Bootstrap start
::start %IEPATH% http://baidu.com
::taskkill /f /im myeclipse.exe
@echo end
::reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v "mineSet" /d "%0"
set :如果路径有空格,需要加引号。
start: /d 表示路径 所以后面跟路径参数, /wait 等该行的可执行文件执行完再执行下一条。
第八行,原本打算用命令行启动myeclipse中引入的tomcat,未成功可忽略。第九行表示开启浏览器,并设置主页url
十行 为杀进程,f ---> force /im 指定要终止的进程的映像名称
最后一行,是将这个文件通过加入到注册表中,设为开机自启项。/v 名称 /d 文件 %0 表示文件本身
(4) 账号
net user admin 123 /add
net localgroup administrators admin /add
net localgroup users admin /del
net user admin /active:yes
net user
net user admin
net user admin /del
“net user admin 123eee /add”--添加名为“admin”,密码为“123eee”的用户,如果不写,则默认密码为空。
“net localgroup administrators admin /add”--将用户“admin”加入“administrators”组
“net localgroup users admin /del”--用户新加进去默认是“users”组,系统会默认你的最低权限。
“net user admin /active:yes”--激活帐号
“net user”--查看所有用户
“net user admin”--查看用户admin
“net user admin /del”--删除用户admin
p:实例1中的三个file本来打算附到附件中,结果发现只能上传图片。。