How to make a batch file execute a reg file

09stephenb picture 09stephenb · Dec 13, 2013 · Viewed 58.5k times · Source

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.

Answer

npocmaka picture npocmaka · Dec 13, 2013
 @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:

set __COMPAT_LAYER=RunAsInvoker

that will prevent UAC pop-up if your script is not ran as administrator.