此bat脚本集成了一些常用的,下面代码块代码复制下来新建bat文件记事本保存为ANSI编码。贴上需要的
个人平时装机折腾的多,基本上没啥特别需求。大量需求封装系统镜像包时已经内置,个别的喜欢单独添加。
[Bash shell] 纯文本查看 复制代码 @echo off&PUSHD %~DP0&TITLE Windows便捷设置批处理脚本x%PROCESSOR_ARCHITECTURE:~-2%
color 0b
FOR /F "tokens=2 delims==" %%l IN ('wmic os get OSLanguage /Value') DO set OSLanguage=%%l
if "%OSLanguage%" NEQ "2052" (
echo Your current operating system language is not Simplified Chinese, about to exit the current window!&pause&exit
)
:: 获取系统桌面路径以保存信息到本地
for /f "tokens=1,2,* " %%i in ('REG QUERY "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "desktop" ^| findstr /i /C:"REG_SZ"') do set "desktoppath=%%k"
:: 格式化桌面路径
set desktoppath=%desktoppath:\\=\%
if exist "%desktoppath%\MAC-INFO.txt" (
del /F/Q %desktoppath%\MAC-INFO.txt
)
::【&&】 连接两个命令,当&&前的命令成功时,才执行&&后的命令。
::【||】 连接两个命令,当||前的命令失败时,才执行||后的命令。
::自动下载需要借助curl指令,低版本系统可能缺少组件,请在[url]https://curl.se/download.html[/url]下载并添加环境变量
Rd "%WinDir%\system32\test_permissions" >NUL 2>NUL
Md "%WinDir%\System32\test_permissions" 2>NUL&&(goto :SelectMenuItem)||(goto :not_admin)
Rd "%WinDir%\System32\test_permissions" 2>NUL
rem 检查脚本是否以管理员身份运行WIn10+有效,win7可能无效!
rem net.exe session 1>NUL 2>NUL && (
rem goto as_admin
rem ) || (
rem goto not_admin
rem )
rem ****************************************************************************
:: 非管理员模式,强制重启脚本
:not_admin
::强制CMD窗口活动代码页编号为GBK简体中文936
chcp 936>nul
echo ******************************************************************
echo ******************************************************************
echo ** **
echo ** **
echo ** 当前非管理员权限,正在强制重启脚本获取权限请稍候... **
echo ** 执行修改中需要修改注册表,如果出现拦截请允许! **
echo ** **
echo ** **
echo ******************************************************************
echo ******************************************************************
%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit
cd /d "%~dp0"
:SelectMenuItem
chcp 936>nul
for /f "tokens=2 delims=={}" %%a in ('wmic PATH Win32_SystemEnclosure get ChassisTypes /value') do (
if %%a==3 (
chcp|findstr /i "936" >nul && (
set ChassisTypes=【台式设备】
) || (
set ChassisTypes=【Desktop computer】
)
) else if %%a==4 (
chcp|findstr /i "936" >nul && (
set ChassisTypes=【台式设备】
) || (
set ChassisTypes=【Desktop computer】
)
) else if %%a==8 (
chcp|findstr /i "936" >nul && (
set ChassisTypes=【笔记本设备】
) || (
set ChassisTypes=【Notebook Computer】
)
) else if %%a==9 (
chcp|findstr /i "936" >nul && (
set ChassisTypes=【笔记本设备】
) || (
set ChassisTypes=【Notebook Computer】
)
) else if %%a==10 (
chcp|findstr /i "936" >nul && (
set ChassisTypes=【笔记本设备】
) || (
set ChassisTypes=【Notebook Computer】
)
)
)
echo #############################################################
echo 1、显示当前操作系统是否为永久激活或给出截止日期
echo #############################################################
echo 2、列出当前操作系统的版本、密钥、激活类型及许可证状态
echo #############################################################
echo 3、列出详细的激活信息,含激活ID、安装ID、激活截止日期
echo #############################################################
echo 4、桌面右键菜单加入新建自定义扩展名文件的选项
echo #############################################################
echo 5、桌面右键菜单加入“新建批处理文件”选项
echo #############################################################
echo 6、添加桌面右键菜单“在此处打开命令行窗口”项
echo #############################################################
echo 7、删除桌面右键菜单“在此处打开命令行窗口”项
echo #############################################################
echo 8、修复程序打开方式异常
echo #############################################################
echo 9、修复资源管理器打不开
echo #############################################################
echo 10、查看本机无线网络连接所有Wifi名称与密码
echo #############################################################
echo 11、获取网卡物理串号地址信息
echo #############################################################
echo 输入编号回车执行查询/修改!(如果出现拦截请允许)&echo.
set /p keywords=请输入编号,Enter键执行修改:
if "%keywords%"=="1" (
goto :GetXprInfo
) else if "%keywords%"=="2" (
goto :GetdliInfo
) else if "%keywords%"=="3" (
goto :GetdlvInfo
) else if "%keywords%"=="4" (
goto :CreateCustomExtensionFileMenuItem
) else if "%keywords%"=="5" (
goto :CreateBatchExtensionFileMenuItem
) else if "%keywords%"=="6" (
goto :CreateBatchMenuItem
) else if "%keywords%"=="7" (
goto :DeleteBatchMenuItem
) else if "%keywords%"=="8" (
echo *************************************************************
echo y|reg add "HKEY_CLASSES_ROOT\exefile\shell\open\command" /ve /t REG_SZ /d "\"%1\" %*" /f
echo 修复完成! &TIMEOUT /T 5 &cls&goto :SelectMenuItem
) else if "%keywords%"=="9" (
echo *************************************************************
echo y|reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v Shell /t REG_SZ /d "Explorer.exe" /f
echo 修复完成! &TIMEOUT /T 5 &cls&goto :SelectMenuItem
) else if "%keywords%"=="10" (
goto :GetWlanInfo
) else if "%keywords%"=="11" (
goto :GetMacAdressInfo
) else (
cls&goto :SelectMenuItem
)
pause&exit
:GetXprInfo
echo *************************************************************
echo 当前%ChassisTypes%系统永久激活状态载入中,请稍等...
slmgr.vbs -xpr
TIMEOUT /T 5 &cls&goto :SelectMenuItem
:GetdliInfo
echo *************************************************************
echo 当前%ChassisTypes%系统版本、密钥、激活类型及许可证状态载入中,请稍等...
slmgr.vbs -dli
TIMEOUT /T 5 &cls&goto :SelectMenuItem
:GetdlvInfo
echo *************************************************************
echo 当前%ChassisTypes%系统激活信息载入中,请稍等...
slmgr.vbs -dlv
TIMEOUT /T 5 &cls&goto :SelectMenuItem
:CreateBatchExtensionFileMenuItem
echo *************************************************************
echo “Windows 批处理文件”右键菜单项添加中,请稍候...
echo y|reg add "HKEY_CLASSES_ROOT\.bat\ShellNew" /v nullfile /t reg_sz /d "" /f
echo y|reg add "HKEY_CLASSES_ROOT\.bat\ShellNew" /v FileName /t reg_expand_sz /d "" /f
echo.&echo ****菜单项创建完成**** &TIMEOUT /T 5 &cls&goto :SelectMenuItem
:CreateCustomExtensionFileMenuItem
echo *************************************************************
echo 新建自定义扩展名文件右键菜单项添加中,请稍候...
echo y|reg add "HKCR\Directory\Background\shell\WinXNew" /v "MUIVerb" /d "新建自定义文件" /f
echo y|reg add "HKCR\Directory\Background\shell\WinXNew" /v "Position" /d "Bottom" /f
echo y|reg add "HKCR\Directory\Background\shell\WinXNew" /v "SubCommands" /d "" /f
echo y|reg add "HKCR\Directory\Background\shell\WinXNew" /v "SeparatorAfter" /d "" /f
echo y|reg add "HKCR\Directory\Background\shell\WinXNew\shell" /ve /d "" /f
echo y|reg add "HKCR\Directory\Background\shell\WinXNew\shell\1.txt" /v "Icon" /d "imageres.dll,-2" /f
echo y|reg add "HKCR\Directory\Background\shell\WinXNew\shell\1.txt" /ve /d "新建自定义空文件" /f
if exist "%windir%\nulname.vbs" (del /q "%windir%\nulname.vbs")
echo y|reg add "HKCR\Directory\Background\shell\WinXNew\shell\1.txt\command" /ve /d "wscript %windir%\nulname.vbs" /f
echo Dim na>>%systemroot%\nulname.vbs
echo na=Inputbox("请输入文件后缀名:","创建自定义扩展名文件","")>>%systemroot%\nulname.vbs
echo If IsEmpty(na) Then>>%systemroot%\nulname.vbs
echo wscript.quit>>%systemroot%\nulname.vbs
echo End If>>%systemroot%\nulname.vbs
echo set fso=createobject("scripting.filesystemobject") : name=^1>>%systemroot%\nulname.vbs
echo while fso.fileexists("NewFile"^&""^&name^&"."^&na)=true>>%systemroot%\nulname.vbs
echo name=name+1>>%systemroot%\nulname.vbs
echo wend>>%systemroot%\nulname.vbs
echo set o=fso.opentextfile("NewFile"^&""^&name^&"."^&na,2,true)>>%systemroot%\nulname.vbs
echo wscript.quit>>%systemroot%\nulname.vbs
echo.&echo ****菜单项创建完成**** &TIMEOUT /T 5 &cls&goto :SelectMenuItem
:CreateBatchMenuItem
echo *************************************************************
echo “在此处打开命令行窗口”右键菜单项添加中,请稍候...
echo y|reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v "%windir%\system32\cmd.exe" /t REG_SZ /d "RUNASADMIN" /f
echo y|reg add "HKEY_CLASSES_ROOT\folder\shell\cmd" /ve /t REG_SZ /d "在此处打开命令行窗口" /f
echo y|reg add "HKEY_CLASSES_ROOT\folder\shell\cmd\command" /ve /t REG_SZ /d "cmd.exe /k cd %%1" /f
echo y|reg add "HKEY_CLASSES_ROOT\Directory\shell\runas" /ve /t REG_SZ /d "在此处打开命令行窗口" /f
echo y|reg add "HKEY_CLASSES_ROOT\Directory\shell\runas" /v HasLUAShield /t REG_SZ /d "" /f
echo y|reg add "HKEY_CLASSES_ROOT\Directory\shell\runas\command" /ve /t REG_SZ /d "cmd.exe /s /k pushd \"%%V\"" /f
echo y|reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\runas" /ve /t REG_SZ /d "在此处打开命令行窗口" /f
echo y|reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\runas" /v HasLUAShield /t REG_SZ /d "" /f
echo y|reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\runas\command" /ve /t REG_SZ /d "cmd.exe /s /k pushd \"%%V\"" /f
echo y|reg add "HKEY_CLASSES_ROOT\Drive\shell\runas" /ve /t REG_SZ /d "在此处打开命令行窗口" /f
echo y|reg add "HKEY_CLASSES_ROOT\Drive\shell\runas" /v HasLUAShield /t REG_SZ /d "" /f
echo y|reg add "HKEY_CLASSES_ROOT\Drive\shell\runas\command" /ve /t REG_SZ /d "cmd.exe /s /k pushd \"%%V\"" /f
echo y|reg add "HKEY_CLASSES_ROOT\LibraryFolder\background\shell\runas" /ve /t REG_SZ /d "在此处打开命令行窗口" /f
echo y|reg add "HKEY_CLASSES_ROOT\LibraryFolder\background\shell\runas" /v HasLUAShield /t REG_SZ /d "" /f
echo y|reg add "HKEY_CLASSES_ROOT\LibraryFolder\background\shell\runas\command" /ve /t REG_SZ /d "cmd.exe /s /k pushd \"%%V\"" /f
echo.&echo ****菜单项创建完成**** &TIMEOUT /T 5 &cls&goto :SelectMenuItem
:DeleteBatchMenuItem
echo *************************************************************
echo “在此处打开命令行窗口”右键菜单项删除中,请稍候...
reg delete "HKEY_CLASSES_ROOT\Directory\shell\runas" /f
reg delete "HKEY_CLASSES_ROOT\Directory\Background\shell\runas" /f
reg delete "HKEY_CLASSES_ROOT\Drive\shell\runas" /f
reg delete "HKEY_CLASSES_ROOT\LibraryFolder\background\shell\runas" /f
echo.&echo ****菜单项删除完成**** &TIMEOUT /T 5 &cls&goto :SelectMenuItem
:GetWlanInfo
chcp|findstr /i "936" >nul && (
cls&echo **********************************************************
echo *********当前%ChassisTypes%已连接WiFi记录列表*************
for /f "tokens=1,2,*" %%i in ('netsh wlan show profiles ^| findstr /i "所有用户配置文件"') do (
echo, WiFi: %%k&echo,WiFi: %%k>>%desktoppath%\MAC-INFO.txt
setlocal enabledelayedexpansion
for /f "delims=" %%a in ('netsh wlan show profile name^="%%k" key^=clear ^| findstr "关键内容"') do (
set "WlanPassword=%%a"
if defined WlanPassword (
set "WlanPassword=!WlanPassword:关键内容=密码!"
set "WlanPassword=!WlanPassword: =!"
echo, !WlanPassword!&echo,!WlanPassword!>>%desktoppath%\MAC-INFO.txt
)
)
echo ==================================================&endlocal
)
) || (
cls&echo **********************************************************
for /f "tokens=1,2,3,*" %%i in ('netsh wlan show profiles ^| findstr /i /C:"All User Profile"') do (
echo, WiFi: %%l
setlocal enabledelayedexpansion
set "WlanName=%%l"
for /f "delims=" %%a in ('netsh wlan show profile name^="!WlanName:: =!" key^=clear ^| findstr /i /C:"Key Content"') do (
set "WlanPassword=%%a"
if defined WlanPassword (
set "WlanPassword=!WlanPassword:Key Content=PassWord!"
set "WlanPassword=!WlanPassword: =!"
echo, !WlanPassword!
)
)
echo ==================================================&endlocal
)
)
goto :GetIPInfo
:GetIPInfo
rem 检测curl下载组件是否存在
curl -V>nul 2>nul&& set "curlVar=load" || set "curlVar="
if defined curlVar (
ping [url]www.baidu.com[/url] -n 1 |find "TTL" >nul && goto :GetNetWlanInfo || goto :onclose
) else (
echo **********************************************************
chcp|findstr /i "936" >nul && (
echo 当前系统CMD缺少curl组件无法在线获取外网IP信息!
) || (
echo The curl component is missing in the CMD of the current system. The curl component cannot obtain the Internet IP address online.
)
echo.&pause&cls&goto :SelectMenuItem
)
:GetNetWlanInfo
echo **********************************************************
chcp|findstr /i "936" >nul && (
echo 当前%ChassisTypes%IP信息获取中请稍候...&echo.
) || (
Please wait while obtaining the current device IP address.&echo.
)
:: 获取外网ip信息
:: [url]https://checkip.amazonaws.com[/url]
:: [url]https://api.ipify.org[/url]
:: [url]https://ifconfig.me/ip[/url]
:: [url]https://icanhazip.com[/url]
:: [url]https://ipinfo.io/ip[/url]
:: [url]https://ipecho.net/plain[/url]
:: [url]https://checkipv4.dedyn.io[/url]
for /f "tokens=4" %%a in ('route print^|findstr 0.0.0.0.*0.0.0.0') do set localIP=%%a
curl -s "https://icanhazip.com" |find ":" >nul && (
for /f %%a in ('curl -# -s "https://icanhazip.com"') do set "NetIPv6=%%a"
)
for /f %%a in ('curl -# -s "https://ifconfig.me/ip"') do set "NetIPv4=%%a"
if not defined NetIPv4 (
for /f %%a in ('curl -# -s "https://ipinfo.io/ip"') do set "NetIPv4=%%a"
)
echo ==============================================>>%desktoppath%\MAC-INFO.txt
if defined localIP (
chcp|findstr /i "936" >nul && (
echo 本机IP:%localIP%&echo 本地IP:%localIP%>>%desktoppath%\MAC-INFO.txt
) || (
echo localIP:%localIP%&echo localIP:%localIP%>>%desktoppath%\MAC-INFO.txt
)
)
if defined NetIPv4 (
chcp|findstr /i "936" >nul && (
echo 外网IPv4:%NetIPv4%&echo IPv4:%NetIPv4%>>%desktoppath%\MAC-INFO.txt
) || (
echo IPv4:%NetIPv4%&echo IPv4:%NetIPv4%>>%desktoppath%\MAC-INFO.txt
)
)
if defined NetIPv6 (
chcp|findstr /i "936" >nul && (
echo 外网IPv6:%NetIPv6%&echo IPv6:%NetIPv6%>>%desktoppath%\MAC-INFO.txt
) || (
echo IPv6:%NetIPv6%&echo IPv6:%NetIPv6%>>%desktoppath%\MAC-INFO.txt
)
)
if exist "%desktoppath%\MAC-INFO.txt" (
chcp|findstr /i "936" >nul && (
echo.&echo 当前查询结果保存在系统桌面WLAN-INFO.txt文件之中。
) || (
echo.&echo The query results are saved in the WLAN-INFO.txt file on the system desktop.
)
)
echo.&pause&cls&goto :SelectMenuItem
:GetMacAdressInfo
cls&echo **********************************************************
chcp|findstr /i "936" >nul && (
echo 当前%ChassisTypes%Mac网卡信息获取中请稍候...
) || (
echo Please wait while obtaining the NIC information of the current device...
)
setlocal enabledelayedexpansion
FOR /F "tokens=*" %%A IN ('IPCONFIG /all 2^>NUL ^|findstr /i /R "描述 Description 物理地址 Physical IPv4 IPv6"') do (
set "MacInfo=%%A"
set "MacInfo=!MacInfo:. =!"
if defined MacInfo (
echo "%%A" | findstr /i "描述 Description" >nul && (
echo ==============================================&echo ==============================================>>%desktoppath%\MAC-INFO.txt
)
echo !MacInfo!&echo !MacInfo!>>%desktoppath%\MAC-INFO.txt
)
)
endlocal
if exist "%desktoppath%\MAC-INFO.txt" (
chcp|findstr /i "936" >nul && (
echo.&echo 当前查询结果保存在系统桌面WLAN-INFO.txt文件之中。
) || (
echo.&echo The query results are saved in the WLAN-INFO.txt file on the system desktop.
)
)
echo.&pause&cls&goto :SelectMenuItem
:onclose
echo **********************************************************
chcp|findstr /i "936" >nul && (
echo 网络连接不的成功,IP信息获取失败!
) || (
echo The current network connection is not successful, the IP information failed to obtain!
)
echo.&pause&cls&goto :SelectMenuItem
|