Solved find and replace registry key value

April 27, 2016 at 23:00:25
Specs: Windows 7
Hello Team,

I need a code that could find a registry key and update its value. The below is the details:

In registry key SYSTEM\CurrentControlSet\Control\Class{4D36E972-E325-11CE-BFC1-08002BE10318} there are lot of sub-hive or folder if I can say like 0000 , 0001 , 0002 , 0003 and so on. Now I need to find a key called "Roamingpreferredbandtype" and need the value to be "2". I need a batch file or vbs so that can deploy it via GPO.

Regards,
Suman Rout


See More: find and replace registry key value

Report •


✔ Best Answer
April 29, 2016 at 18:37:30
Okay, I'll bite. Is "Roamingpreferredbandtype" a DWORD, string value, or something else?

EDIT: I assume Sumann has already found his answer somewhere else, but for completion's sake, and assuming Roamingpreferredbandtype is a DWORD:

Const nicName = "NicNameHere"
Const regPath = "SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}"
Set reg = GetObject("winmgmts:root\default:StdRegProv")
reg.EnumKey &H80000002, regPath, keys
For Each key In keys
  key = regPath & "\" & key
  If reg.GetStringValue(&H80000002, key, "DriverDesc", deviceName) = 0 _
   And InStr(deviceName, nicName) Then _
    reg.SetDWORDValue(&H80000002, key, "Roamingpreferredbandtype", 2)
Next 'key

How To Ask Questions The Smart Way

message edited by Razor2.3



#1
April 27, 2016 at 23:52:15
You can just type the full key and value you want to replace, then use the /F parameter.

Enter

REG ADD /?
in cmd to see how to use and how things work.

Don't worry if plan A fails, there are 25 more letters in the alphabet ;)

message edited by RainBawZ


Report •

#2
April 28, 2016 at 01:21:53
No this does not work.
I don't want to create a key I just want to update the key with the new value.
Also not just anywhere find the key and then make the change to the particular key.

Regards,
Suman Rout


Report •

#3
April 28, 2016 at 10:31:03
Rainbawz' solution should work. REG ADD with /F will overwrite an existing key, so there's no reason I know of that it wouldn't work. If you need to search for a key, you can use reg query with the /F option.
Here's an alternative scenario: First, using REGEDIT, find the target key, change it's value to "2", and export it. This should only need to be done once, to set up the file. The file (f/example xxx.reg) will be permanent. To change the value in the registry, use: reg import xxx.reg
I would advise write-protecting this file just for some insurance, since it affects the registry. Rainbawz's solution is preferable because it doesn't require this extra file.

message edited by nbrane


Report •

Related Solutions

#4
April 29, 2016 at 15:11:05
An easier way would be to use WMI's Win32_NetworkAdapter to find the subkey you desire. Search for the adapter's name, and the returned DeviceID will be the one you're looking for, e.g. DeviceID 23 would be ...\{4D36E972-E325-11CE-BFC1-08002BE10318}\0023

How To Ask Questions The Smart Way


Report •

#5
April 29, 2016 at 18:37:30
✔ Best Answer
Okay, I'll bite. Is "Roamingpreferredbandtype" a DWORD, string value, or something else?

EDIT: I assume Sumann has already found his answer somewhere else, but for completion's sake, and assuming Roamingpreferredbandtype is a DWORD:

Const nicName = "NicNameHere"
Const regPath = "SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}"
Set reg = GetObject("winmgmts:root\default:StdRegProv")
reg.EnumKey &H80000002, regPath, keys
For Each key In keys
  key = regPath & "\" & key
  If reg.GetStringValue(&H80000002, key, "DriverDesc", deviceName) = 0 _
   And InStr(deviceName, nicName) Then _
    reg.SetDWORDValue(&H80000002, key, "Roamingpreferredbandtype", 2)
Next 'key

How To Ask Questions The Smart Way

message edited by Razor2.3


Report •


Ask Question