程序员每天开机的第一步就是开启各种环境(当然不想设置开机启动)、软件,写个dos脚本自动执行就好了,下班的时候也是写个脚本自动清理进程关机就好。
结束进程:
@echo off ::阿里云盘 tasklist /nh | find "aDrive.exe" if ERRORLEVEL 1 (echo "aDrive not found") else (taskkill /f /im aDrive.exe /t) ::phpstorm tasklist /nh | find "phpstorm64.exe" if ERRORLEVEL 1 (echo "phpstorm64 not found") else (taskkill /f /im phpstorm64.exe /t) ::谷歌浏览器 tasklist /nh | find "chrome.exe" if ERRORLEVEL 1 (echo "chrome not found") else (taskkill /f /im chrome.exe /t) ::phpstudy tasklist /nh | find "phpstudy_pro.exe" if ERRORLEVEL 1 (echo "phpstudy_pro not found") else (taskkill /f /im phpstudy_pro.exe /t) ::阿里邮箱 tasklist /nh | find "Alimail.exe" if ERRORLEVEL 1 (echo "Alimail not found") else (taskkill /f /im Alimail.exe /t) ::微信 tasklist /nh | find "WeChat.exe" if ERRORLEVEL 1 (echo "WeChat not found") else (taskkill /f /im WeChat.exe /t) ::按回车后关闭dos窗口 pause
启动进程:
@echo off ::Program Files (x86) 和Program Files需要特殊注意(也可以直接用双引号包起来目录名称,最后有说明),分别用Progra~2 和Progra~1代替 ::当windows的长文件名在dos系统下使用时,会被截取为前6位+~数字的格式;在C盘的文件夹我遇到了这种情况。 ::微信 tasklist /nh | find "WeChat.exe" if ERRORLEVEL 1 (echo "WeChat is starting " && start C:\Progra~2\Tencent\WeChat\WeChat.exe ) else ( echo "WeChat is running " ) ::阿里云盘 tasklist /nh | find "aDrive.exe" if ERRORLEVEL 1 (echo "aDrive is starting " && start C:\Users\wei\AppData\Local\Pxxxx\aDrive\aDrive.exe ) else ( echo "aDrive is running " ) ::phpstorm tasklist /nh | find "phpstorm64.exe" if ERRORLEVEL 1 (echo "phpstorm is starting " && start D:\Users\wei\Downloads\Compressed\Pxxxx\pstorm64.exe ) else ( echo "phpstorm is running " ) ::谷歌浏览器 tasklist /nh | find "chrome.exe" if ERRORLEVEL 1 (echo "chrome is starting " && start C:\Users\wei\AppData\Local\Pxxxx\chrome.exe ) else ( echo "chrome is running ") ::阿里邮箱 tasklist /nh | find "Alimail.exe" if ERRORLEVEL 1 (echo "Alimail is starting " && start C:\ProgramData\Pxxxx\Alimail.exe ) else ( echo "Alimail is running " ) ::phpstudy tasklist /nh | find "phpstudy_pro.exe" if ERRORLEVEL 1 (echo "phpstudy is starting " && start D:\Pxxxx\Pxxxx\phpstudy_pro.exe ) else ( echo "phpstudy_pro is running " ) pause
需要注意的就是启动的时候特殊目录的问题:
::Program Files (x86) 和Program Files需要特殊注意,分别用Progra~2 和Progra~1代替 ::当windows的长文件名在dos系统下使用时,会被截取为前6位+~数字的格式;在C盘的文件夹我遇到了这种情况。
也可以直接用双引号把目录包起来执行,比如(判断phpstorm是否已经启动,否则启动它):
::phpstorm tasklist /nh | find "phpstorm64.exe" if ERRORLEVEL 1 (echo "phpstorm is starting " && start D:\"Program Files"\JetBrains\"PhpStorm 2020.1"\bin\phpstorm64.exe ) else ( echo "phpstorm is running " )
dos 命令一行执行多条用“&”或者“&&”,前者代表无需前面的执行成功也可以执行后面的,后者代表执行完成前面的命令再执行后面的