Run reg command in cmd (bat file)? Run reg command in cmd (bat file)? windows windows

Run reg command in cmd (bat file)?


You will probably get an UAC prompt when importing the reg file. If you accept that, you have more rights.

Since you are writing to the 'policies' key, you need to have elevated rights. This part of the registry protected, because it contains settings that are administered by your system administrator.

Alternatively, you may try to run regedit.exe from the command prompt.

regedit.exe /S yourfile.reg

.. should silently import the reg file. See RegEdit Command Line Options Syntax for more command line options.


In command line it's better to use REG tool rather than REGEDIT:

REG IMPORT yourfile.reg

REG is designed for console mode, while REGEDIT is for graphical mode.This is why running regedit.exe /S yourfile.reg is a bad idea, since you will not be notified if the there's an error, whereas REG Tool will prompt:

>  REG IMPORT missing_file.regERROR: Error opening the file. There may be a disk or file system error.>  %windir%\System32\reg.exe /?REG Operation [Parameter List]  Operation  [ QUERY   | ADD    | DELETE  | COPY    |               SAVE    | LOAD   | UNLOAD  | RESTORE |               COMPARE | EXPORT | IMPORT  | FLAGS ]Return Code: (Except for REG COMPARE)  0 - Successful  1 - FailedFor help on a specific operation type:  REG Operation /?Examples:  REG QUERY /?  REG ADD /?  REG DELETE /?  REG COPY /?  REG SAVE /?  REG RESTORE /?  REG LOAD /?  REG UNLOAD /?  REG COMPARE /?  REG EXPORT /?  REG IMPORT /?  REG FLAGS /?


If memory serves correct, the reg add command will NOT create the entire directory path if it does not exist. Meaning that if any of the parent registry keys do not exist then they must be created manually one by one. It is really annoying, I know! Example:

@echo offreg add "HKCU\Software\Policies"reg add "HKCU\Software\Policies\Microsoft"reg add "HKCU\Software\Policies\Microsoft\Internet Explorer"reg add "HKCU\Software\Policies\Microsoft\Internet Explorer\Control Panel"reg add "HKCU\Software\Policies\Microsoft\Internet Explorer\Control Panel" /v HomePage /t REG_DWORD /d 1 /fpause