how to add reg key from batch file

0

I have a batch file named pp.bat and converted to pp.exe using bat2exe tool. It works. I want to add this key to my batch file :

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
"p"="c:\\pp.exe"

so that it runs when windows starts. The batch code of my file is:

@ECHO OFF
SET /a VAR=0 
:HOME 
SET /a VAR=VAR+1  
IF %VAR%==3 goto :End  
start www.google.com 
goto :HOME 
:END

bee4u

Posted 2015-10-24T10:19:38.660

Reputation: 3

Possible duplicate of Adding key to registry

– Ƭᴇcʜιᴇ007 – 2016-01-07T21:46:08.963

Answers

2

The regedit tool can be run from the command-line as detailed in How to add, modify, or delete registry subkeys and values by using a .reg file :

to silently run the .reg file (with the /s switch) from a login script batch file, use the following syntax:

regedit.exe /spath of .reg file

You can also (as noted in Adding key to registry) use reg add to add a key. That answer gives (without clues regarding syntax, etc), this example:

REG ADD HKLM\Software\MyCo /v Data /t REG_BINARY /d fe340ead

making it not useful. If it had been useful, this would be a duplicate.

From the documentation, and matching it to your key, you might use this command:

REG ADD HKLM\Software\Microsoft\Windows\CurrentVersion\Run /v "p" /t REG_SZ /d "c:\\pp.exe"

That is,

  • using reg add,
  • specify as "HKLM\Software\Microsoft\Windows\CurrentVersion\Run",
  • specify the name of the registry key as "p",
  • specify the type as REG_SZ (a string), and
  • specify the data (key's value) as "c:\\pp.exe"

The "\\" in your key's value looks odd. You might want to check that.

Thomas Dickey

Posted 2015-10-24T10:19:38.660

Reputation: 6 891

It worked and you are right about "\" its a "" . Thx @ Thomas Dickey – bee4u – 2015-10-24T14:44:42.140

Yes definitely "accepted" – bee4u – 2015-10-24T14:49:09.547