Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run reg command in cmd (bat file)?

I'm trying to run this reg code in cmd (bat file), but I couldn't make it work. Where am I doing wrong?

[HKEY_CURRENT_USER\Software\Policies\Microsoft\Internet Explorer\Control Panel]
"HomePage"=dword:00000001

It works if I make it a reg file and double click.

Bat file code (this doesn't work, no errors):

@echo off
reg add "HKCU\Software\Policies\Microsoft\Internet Explorer\Control Panel" /V HomePage /T REG_DWORD /F /D 1
like image 688
user198989 Avatar asked Dec 10 '12 21:12

user198989


2 Answers

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.

like image 157
GolezTrol Avatar answered Oct 14 '22 20:10

GolezTrol


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

ERROR: 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 - Failed

For 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 /?
like image 76
Noam Manos Avatar answered Oct 14 '22 19:10

Noam Manos