windows 如何使批处理文件执行reg文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20563975/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make a batch file execute a reg file
提问by 09stephenb
I have the following code
我有以下代码
@echo off
file.reg
pause
This works but when the batch file is elevated I get an error saying that it cannot find the file. does any one know what I am doing wrong.
这有效,但是当批处理文件被提升时,我收到一条错误消息,说它找不到该文件。有谁知道我做错了什么。
回答by npocmaka
@echo off
rem set __COMPAT_LAYER=RunAsInvoker
REGEDIT.EXE /S "%~dp0\file.reg"
pause
Try this
尝试这个
If you are accessing locations in the registry that does not require admin privileges you can use __COMPAT_LAYER
environment variable.Just execute this before using regedit:
如果您正在访问不需要管理员权限的注册表中的位置,您可以使用__COMPAT_LAYER
环境变量。只需在使用 regedit 之前执行以下操作:
set __COMPAT_LAYER=RunAsInvoker
that will prevent UAC pop-up if your script is not ran as administrator.
如果您的脚本不是以管理员身份运行,这将阻止 UAC 弹出。
回答by LS_???
Probably, starting batch with elevated privileges will change starting directory to %windir%\system32
(path where cmd.exe
is located).
可能,以提升的权限启动批处理会将起始目录更改为%windir%\system32
(所在路径cmd.exe
)。
Use:
用:
"%~dp0\file.reg"
to always execute file.reg
located in same directory as batch file.
始终file.reg
在与批处理文件相同的目录中执行。
Also consider using REG
command, as it allows you to perform console operations on registry (check REG /?
).
还可以考虑使用REG
命令,因为它允许您对注册表执行控制台操作(检查REG /?
)。