题
如何运行到从cmd的regedit中的指定路径?我想为特定服务添加新密钥。有人能帮我吗?我想从C#代码那样做到这一点,但首先我正在尝试从CMD做到这一点。thx
我想从cmd到hkey_local_machine \ system \ currentControlset \ Services \ Service,并在服务服务中添加一个具有值的新密钥。我确实在cmd:regedit "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Service" add /v KeyName Parameters
中写入,但我有一个错误说它无法加载文件。为什么?
解决方案
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
其他提示
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
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?.