以下批处理脚本将分别导出当前用户的用户变量 PATH 和系统变量 PATH,并将它们分别保存到带有当前日期和时间前缀的文本文件中。

@echo off
setlocal enabledelayedexpansion

:: Change the working directory to the script's directory
cd /d %~dp0

:: Get the current date and time and format it as YYYYMMDD_HHMMSS
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "datetime=%%a"
set "datetime=%datetime:~0,8%_%datetime:~8,6%"

:: Export current user PATH to a text file with the date and time prefix
for /f "tokens=2* delims= " %%a in ('reg query HKCU\Environment /v PATH') do echo %%b > %datetime%_user_PATH_backup.txt
echo Current user PATH has been backed up to %datetime%_user_PATH_backup.txt

:: Export system PATH to a text file with the date and time prefix
for /f "tokens=2* delims= " %%a in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v PATH') do echo %%b > %datetime%_system_PATH_backup.txt
echo System PATH has been backed up to %datetime%_system_PATH_backup.txt

pause
运行此脚本后,您将在当前目录下看到两个备份文件,分别为 YYYYMMDD_HHMMSS_user_PATH_backup.txt 和 YYYYMMDD_HHMMSS_system_PATH_backup.txt(其中 YYYYMMDD_HHMMSS 是当前日期和时间)。这两个文件分别包含用户变量 PATH 和系统变量 PATH 的备份。

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部