Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a batch file execute a reg file

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.

like image 452
09stephenb Avatar asked Dec 13 '13 10:12

09stephenb


2 Answers

 @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.

like image 99
npocmaka Avatar answered Oct 14 '22 19:10

npocmaka


Probably, starting batch with elevated privileges will change starting directory to %windir%\system32 (path where cmd.exe is located).

Use:

"%~dp0\file.reg"

to always execute file.reg located in same directory as batch file.

Also consider using REG command, as it allows you to perform console operations on registry (check REG /?).

like image 44
LS_ᴅᴇᴠ Avatar answered Oct 14 '22 19:10

LS_ᴅᴇᴠ