试试- @echo off
-
- set backupDir=C:\Windows\System32\Backup
- set timeStamp=%date:~4%_%time:~0,2%%time:~3,2%
- set serviceName=
- set serviceNameList= # 用空格分隔
-
- if not exist "%backupDir%" (
- mkdir "%backupDir%"
- )
-
- if [%1]==[] (
- echo Usage: %0 [service name]...
- echo.
- echo Examples:
- echo Backup a single service:
- echo %0 wuauserv
- echo.
- echo Backup multiple services:
- echo %0 wuauserv sppsvc
- echo.
- pause
- exit /b 1
- ) else (
- set "serviceNameList=%*"
- )
-
- for %%s in (%serviceNameList%) do (
- set "serviceName=%%s"
- set "backupFile=%backupDir%\%serviceName%_%timeStamp%.reg"
-
- reg export "HKLM\SYSTEM\CurrentControlSet\Services\!serviceName!" "!backupFile!" /y >nul
-
- if not errorlevel 1 (
- echo Service !serviceName! backed up to !backupFile!
- ) else (
- echo Failed to backup service !serviceName!
- )
- )
-
- pause
复制代码 运行上述脚本时,输入要备份的 Windows 服务名称。脚本将根据输入生成备份文件,并保存到 `C:\Windows\System32\Backup` 目录中。如果未指定服务名称,则会显示帮助信息。
ps:需要使用管理员权限运行。你可以进行适当修改来使用 |