9

how can i run to a specify path in regedit from cmd? I would like to add a new key to a specific service. Can someone help me? I would like to do this from a c# code, but first i am trying to do it from cmd. Thx

i would like to navigate from cmd to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Service and add in the Service service a new key with a value. i did write in cmd: regedit "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Service" add /v KeyName Parameters but i have an error saying that it can't load the file. why?

elisa
  • 743
  • 2
  • 13
  • 31

3 Answers3

13

you can use

reg add "HKLM\SYSTEM\CurrentControlSet\services\Service" /v "KeyName" /d "Parameters" /f

Which would create a value (/v) named KeyName with data containing Parameters. the /f switch is used to override any confirmations and interruptions so the command can be executed without user input,omit for testing. additionaly,you can replace /v with /ve (value empty) and not specify a value name at all. this allows writting data (/d) to the default key value. also,if the path you intent to write to doesn't exist,the keys will be created without any warning.

for more information type reg /? in the command line

9

To add a Registry Entry from cmd using regedit, create a *.reg file containing the data you want to add. Simple example:

Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\TestKey]
"TestDWORD"=dword:00000123

and then execute this: regedit /s myreg.reg

This adds a Key (displayed like a folder in the regedit browser) named TestKey to HKEY_CURRENT_USER\Software. The TestKey Key contains a DWORD entry named "TestDWORD" that contains 123 in hex (291 in decimal)


Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\TestKey]
"TestDWORD"=dword:00000123

[HKEY_CURRENT_USER\Software\TestKey\SubKey]
"StringEntry"="StringValue"

This creates TestKey @ HKEY_CURRENT_USER\Software plus a sub-key "SubKey" of TestKey with a String Entry (named "StringEntry") and value of "StringValue"

There's a simple way to find out how to create different kinds of entries: Use the regedit gui to create the desired entries, then mark the key and use the Menu File -> Export. The generated file will contain the key(s) and it's entries.


To create a Registry Entry in C#: http://msdn.microsoft.com/en-us/library/h5e7chcf.aspx

BatteryBackupUnit
  • 12,934
  • 1
  • 42
  • 68
  • thx a lot. My value is a string value. How can i write that in the .reg file? – elisa Mar 31 '11 at 07:52
  • i would like to add a subkey with a value. how to do it? – elisa Mar 31 '11 at 08:21
  • 1
    There's a simple way to find that out: Use the regedit gui to create the desired entries, then mark the key and use the Menu File -> Export. The generated file will contain the key(s) and it's entries. Edit: moved example to Answer for better display. – BatteryBackupUnit Apr 01 '11 at 08:12
0

I don't know what "run to a specify path in regedit from cmd" means.

However, if you want set a registry key from a batch file, just create a .reg file by exporting it from Regedit, then run reg import [filename.reg] (where [filename.reg] is the name of the file you exported).

If you want to open up Regedit to show a certain key, see How to launch Windows' RegEdit with certain path?.

Community
  • 1
  • 1
Gabe
  • 84,912
  • 12
  • 139
  • 238
  • i want to nagivate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Service where Service is a service i create and add here a new KEY with a value. – elisa Mar 30 '11 at 15:19
  • @elisa: If you want to navigate automatically within Regedit and manually add a key, read my last paragraph. If you want to automatically add a new key to the registry, see my middle paragraph. There is no easy way to automatically navigate *and* add a key within Regedit. – Gabe Mar 30 '11 at 15:32
  • i would like to add a subkey with a string value and reg_sz and data: a path file to a specific path and key. how to do it? – elisa Mar 31 '11 at 08:22