批处理编程之实例篇

1、打开网页后,最小化:

start /min iexplore http://www.baidu.cn

清除Delphi编程中的垃圾文件:
@color a
@echo off
for /r “D:\Program Files\Borland\Projects” %%i in (*.~* *.obj *.dcu *.hpp *.dcp *.dpl *.cesettings *.bak *.ddp *.dof *.cfg *.aps) do (echo 正在清除 %%i
del “%%i”)
echo 清除完毕!
pause>nul
不能写成 for /r “..\” 表示在当前目录下,防止误删

语音功能:mshta vbscript:createobject(“sapi.spvoice”).speak(“I love bathome”)(window.close)

实现启动notepad,输入ABC ,然后最小化
Set ws = CreateObject(“Wscript.Shell”)
ws.run “cmd /c start notepad.exe”,vbhide
wscript.sleep 2000
ws.sendkeys “A”
ws.sendkeys “B”
ws.sendkeys “C”
wscript.sleep 1000
ws.sendkeys “%”
ws.sendkeys ” ”
ws.sendkeys “n”

ws.sendkeys “%” 发送%就是发送了alt键
ws.sendkeys ” ” 这里发送了按键
ws.sendkeys “n” 这句话的意思就是发送了n

批处理整理IP的代码:
@echo off
color a
for /f “eol=- tokens=1 delims= ” %%i in (result.txt) do echo %%i>>1.txt
for /f “eol=P tokens=1 delims= ” %%i in (1.txt) do echo %%i>>2.txt
for /f “eol=S tokens=1 delims= ” %%i in (2.txt) do echo %%i>>Open.txt
del 1.txt
del 2.txt

刷网页的代码:
for /f “eol=;” %%i in (1.txt) do (start %%i && ping -n 7 127.1>nul && taskkill /f /im IEXPLORE.EXE && ping -n 2 127.1>nul)
其中1.txt中填好一些网址   eol=;表示;为注释作用,忽略掉

@color a
@echo off
for /r “G:\电影” %%i in (*.RMVB) do (echo %%~ni)
pause>nul