BAT/CMD 命令整理
2022/7/19大约 5 分钟约 1517 字
BAT/CMD 命令整理
powershell 向导 - TutorialsPoint
注意
以下命令均需要保存为 .bat 或 .cmd 后缀的文件才能执行,并且使用 ANSI 编码(不能是 UTF-8 编码)。
系统相关
判断系统位数
@echo off
rem 判断64位系统和32位系统
if /i %PROCESSOR_IDENTIFIER:~0,3%==x86 (
echo 32位操作系统
) else (
echo 64位操作系统
)
pause
rem https://blog.csdn.net/yhcad/article/details/90199086获取系统信息
@echo off
color 3f
mode con cols=60 lines=20
title 系统版本获取
:: 开始获取系统版本
if /i not "%os%"=="Windows_NT" (set TheOS=非Windows系统&set TheBit=) else (
ver | find "4.0" > nul && set TheOS=Windows 95
ver | find "4.10"> nul && set TheOS=Windows 98
ver | find "4.90"> nul && set TheOS=Windows me
ver | find "3.51"> nul && set TheOS=Windows NT35
ver | find "5.0" > nul && set TheOS=Windows 2000
ver | find "5.1" > nul && set TheOS=Windows XP
ver | find "5.2" > nul && set TheOS=Windows 2003
ver | find "6.0" > nul && set TheOS=Windows Vista
ver | find "6.1" > nul && set TheOS=Windows 7
ver | find "6.2" > nul && set TheOS=Windows 8
ver | find "10.0"> nul && set TheOS=Windows 10
set TheBit=x%PROCESSOR_ARCHITECTURE:~-2%
)
:: 完成获取
echo 您的系统版本:%TheOS% %TheBit%
pause
exit
rem https://blog.csdn.net/fxziyu/article/details/85119225清理 C 盘(以前 XP 系统常用)
@echo off
color 0a
title C盘垃圾清理
echo 正在清除系统垃圾文件,请稍等......
del /f /s /q %SystemDrive%\*.tmp %删除系统盘目录下临时文件%
del /f /s /q %SystemDrive%\*._mp %删除系统盘目录下临时文件%
del /f /s /q %SystemDrive%\*.log %删除系统盘目录下日志文件%
del /f /s /q %SystemDrive%\*.pf %删除系统盘目录下预读文件%
::del /f /s /q %SystemDrive%\*.gid %删除系统盘目录下GID文件(属于临时文件,具体作用不详)%
del /f /s /q %SystemDrive%\*.chk %删除系统目录下scan disk(磁盘扫描)留下的无用文件%
del /f /s /q %SystemDrive%\*.old %删除系统目录下old文件(Windows更新备份文件)%
del /f /s /q %SystemDrive%\recycled\*.* %删除回收站的无用文件%
del /f /s /q %WinDir%\*.bak %删除系统目录下备份文件%
del /f /s /q %WinDir%\prefetch\*.* %删除应用程序临时文件
rd /s /q %WinDir%\temp & md %WinDir%\temp %删除系统维护等操作产生的临时文件%
del /f /q %UserProfile%\cookies\*.* %删除当前用户的COOKIE(IE)%
del /f /s /q "%UserProfile%\Local Settings\Temporary Internet Files\*.*" %删除internet临时文件%
del /f /s /q "%UserProfile%\Local Settings\Temp\*.*" %删除当前用户日常操作临时文件%
del /f /s /q "%UserProfile%\recent\*.*" %删除访问记录(开始菜单中的文档里面的东西)%
echo 清除系统垃圾完成!
echo. & pause查看连接过的 WiFi 密码
@echo off
title 本机连接过的WIFI及密码
echo *************************************
for /f "tokens=3*" %%i in ('netsh wlan show profiles ^| findstr "所有用户配置文件"') do (
call :GetPass %%i %%j
)
echo.
pause
:GetPass
echo WiFi: %*
for /f "delims=: tokens=2-3" %%a in ('netsh wlan show profile name^="%*" key^=clear ^| findstr "关键内容"') do (
echo 密码: %%a
)
echo -------------------------------------打开声音面板
@echo off
if not "%~1"=="p" start /min cmd.exe /c %0 p&exit
rundll32.exe shell32.dll,Control_RunDLL mmsys.cpl立即锁住电脑(相当于 Win+L)
rundll32.exe user32.dll,LockWorkStationLaTeX 常用
清理辅助文件
@echo off
del /q *.aux *.bbl *.blg *.log *.out *.toc *.bcf *.xml *.synctex *.nlo *.nls *.bak *.ind *.idx *.ilg *.lof *.lot *.ent-x *.tmp *.ltx *.los *.lol *.loc *.listing *.gz *.userbak *.nav *.snm *.vrb *.synctex(busy)
del /q *.nav *.snm *.vrb *.fls *.xdv *.fdb_latexmk查看本机安装的字体
@echo off
::fc-list :lang=zh >font.txt
fc-list -f "%%{family}\n" :lang=zh >d:zh-font.txt
start d:zh-font.txt
ping -n 2 127.1>nul
del d:zh-font.txt重启 explorer
@echo off
taskkill /im explorer.exe /f
ping -n 2 127.0.0.1 > nul ::这里相当于延时 1 秒再运行以下指令
start explorer.exe小玩意儿
将压缩包“藏”进图片
合并后将后缀名改为 .zip 可以正常解压
@echo off
mode con lines=15 cols=60
title Pic Blender
echo 拖入图片到此,然后回车&set /p pic=&cls
echo 拖入压缩包到此,然后回车&set /p zip=&cls
:: 图片和压缩包路径
set bat=%temp%\temp.bat
echo %pic%>%bat%
for /f "delims==" %%i in (%bat%) do (
set pn=%%~ni
set pt=%%~xi
)
:: 保留图片文件名和后缀
copy %pic%/b+%zip%/b=%pn%_new%pt%>nul
:: 核心所在
echo @echo off>%bat%
echo %%1 start /min cmd.exe /c %%0 :^&exit>>%bat%
echo mshta vbscript:msgbox^("完成,生成的图片在原图片所在文件夹",64,"完成"^)^(window.close^)>>%bat%
echo del /f /q %%0>>%bat%
:: 生成提示框的bat
call %bat%
:: choice /t 5 /d y /n >nul关闭打开应用时的安全警告弹窗
主要是打开用户账户控制设置界面,按下 Win+R 输入 UserAccountControlSettings 回车即可。
也可以将下面的另存为 *.{bat,cmd} 然后运行:
@echo off
if not "%~1"=="p" start /min cmd.exe /c %0 p & exit
mshta vbscript:msgbox("在接下来弹出的窗口中,将控制按钮滑至最底格,单击“确定”;"^&vbCrLf^&"最后在系统弹出的窗口中选择“是”即可完成",64,"提示")(window.close)
start %winDir%\system32\UserAccountControlSettings.exe修改文件属性
有些时候我们想要修改一些属性,例如创建时间、修改时间、访问时间等,通过 PowerShell 可以实现这个需求,不需要下载其他小工具:
# 将 修改时间 和 访问时间 修改为 2023-01-05 11:30:00
Set-ItemProperty -Name LastWriteTime -Value "2023-01-05 11:30:00" -Path D:\test.docx
Set-ItemProperty -Name LastAccessTime -Value "2023-01-05 11:30:00" -Path D:\test.docx
# 设置文件为非只读
Set-ItemProperty -Name IsReadOnly -Value False -Path D:\test.docx常用的属性列举如下:
Name:文件名Extension:后缀,如.docxIsReadOnly:是否只读CreationTime:创建时间LastWriteTime:修改时间LastAccessTime:访问时间
我们也可以通过 Get-ItemProperty 函数查看文件属性:
Get-ItemProperty -Path E:\test.docx | Format-list -Property * -Force如果想要修改只读、隐藏、是否为系统文件等属性,可以用 attrib 命令,参考 help attrib。
查看回收站大小
单独查看 D 盘回收站:
$sum = (Get-ChildItem -Path 'D:\$Recycle.bin' -Recurse -File -Force -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum; if (!$sum) { $sum = 0 }; '{0:N2} MB' -f ($sum / 1MB)总共大小:
$recycle = (New-Object -ComObject Shell.Application).NameSpace(10) # 10 代表回收站
$totalSize = 0; $recycle.Items() | ForEach-Object { $totalSize += $_.Size }
'{0:N2} MB' -f ($totalSize /1MB)