You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何创建程序重命名Program Files中exe及Windows注册表文件夹

实现EXE文件与注册表项重命名的批处理方案

你已经掌握了同目录下EXE文件的重命名方法,接下来解决注册表项重命名的问题——Windows原生命令行没有直接重命名注册表项的命令,我们可以通过导出-修改-导入-删除原项的流程实现,下面是整合后的完整批处理脚本:

完整批处理代码

@echo off
title 重命名工具
pushd "%~dp0" >nul 2>&1

:: 1. 重命名同目录下的EXE文件
ren "Program1.exe" "Program2.exe"

:: 2. 重命名指定注册表项(示例:HKLM\SOFTWARE\Program1 → HKLM\SOFTWARE\Program2)
set "OldRegPath=HKEY_LOCAL_MACHINE\SOFTWARE\Program1"
set "NewRegPath=HKEY_LOCAL_MACHINE\SOFTWARE\Program2"
set "TempRegFile=%temp%\TempRegModify.reg"

:: 导出原注册表项到临时文件
reg export "%OldRegPath%" "%TempRegFile%" /y >nul 2>&1
if %errorlevel% neq 0 (
    echo 导出注册表项失败,请确保以管理员身份运行脚本!
    pause
    exit /b 1
)

:: 使用PowerShell替换注册表路径(兼容Windows 7及以上版本)
powershell -Command "(Get-Content '%TempRegFile%') -replace '%OldRegPath%', '%NewRegPath%' | Set-Content '%TempRegFile%'"

:: 导入修改后的注册表项
reg import "%TempRegFile%" >nul 2>&1
if %errorlevel% neq 0 (
    echo 导入注册表项失败!
    pause
    exit /b 1
)

:: 删除原注册表项
reg delete "%OldRegPath%" /f >nul 2>&1
if %errorlevel% neq 0 (
    echo 删除原注册表项失败!
    pause
    exit /b 1
)

:: 清理临时文件
del "%TempRegFile%" >nul 2>&1

echo 重命名操作全部完成!
pause
exit

关键注意事项

  • 必须以管理员身份运行:修改HKEY_LOCAL_MACHINE下的注册表项需要管理员权限,右键点击批处理文件选择「以管理员身份运行」。
  • 路径准确性:确保OldRegPath和NewRegPath的写法完全匹配目标注册表项,路径错误会导致操作失败。
  • 兼容性:脚本使用的PowerShell命令兼容Windows 7及以上主流系统,无需额外安装工具。

内容的提问来源于stack exchange,提问作者Constanza

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 23:55:37