rschraeger
asked on
Change Value in Registry not working
I have a script that searches a registry for a value and if its 0 change it to a 1. I can find the key but it will not write the value.
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set oReg=GetObject("winmgmts:\\" &_
strComputer & "\root\default:StdRegProv")
For x=0 to 9
strKeyPath = "SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\000"& x
strValueName = "LOM"
oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
If strValue="0" then
oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,1
End If
Next
For x=10 to 99
strKeyPath = "SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\00"& x
strValueName = "LOM"
oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
If strValue="0" Then
oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,1
End If
Next
Here http://forums.speedguide.net/showthread.php?253346-RE-Switching-between-wired-and-wireless is another version that is for XP.
ASKER
I tired that script but it does not work. The syntax is wrong. I am acutal looking for someone to help me with my script rather then suggest a different script.
Saturdays are some times slow. If no one else helps, click on "Request Attention" above to get others to look at your question.
Hi,
values you are trying to set are string only?
values you are trying to set are string only?
You can try the following
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set oReg=GetObject("winmgmts:\\" &_
strComputer & "\root\default:StdRegProv")
For x=0 To 9
strKeyPath = "SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\000"& x
strValueName = "LOM"
oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
If strValue="0" Then
strvalue1="1"
oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strvalue1
End If
Next
For x=10 To 99
strKeyPath = "SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\00"& x
strValueName = "LOM"
oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
If strValue="0" Then
strvalue1="1"
oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strvalue1
End If
Next
ASKER
still did not work
can you give the following inside the if <condition>, to check if condition is true for any value
wscript.echo strvalue
wscript.echo strvalue
ASKER
I did the echo's before and the condition comes back correctly.
You are using the following
To get value - oReg.GetExpandedStringValu e
To set Value - oReg.SetStringValue
Try using oReg.SetExpandedStringValu e for setting the value
To get value - oReg.GetExpandedStringValu
To set Value - oReg.SetStringValue
Try using oReg.SetExpandedStringValu
ASKER
No change after setting the oReg.SetExpandedStringValu e
hmmm...I have tested the code you have posted and works perfectly...without any issue..
No errors are returned? Do you have the required privileges?
No errors are returned? Do you have the required privileges?
ASKER
I get a complete error code too but the setting is not changed in my registry. I am running it with admin privledges. I am running this under a Windows 7 client.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.