Link to home
Start Free TrialLog in
Avatar of rschraeger
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

Open in new window

Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Avatar of rschraeger
rschraeger

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?
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

Open in new window

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
I did the echo's before and the condition comes back correctly.
You are using the following

To get value - oReg.GetExpandedStringValue

To set Value - oReg.SetStringValue

Try using oReg.SetExpandedStringValue for setting the value
No change after setting the  oReg.SetExpandedStringValue
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?
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
Avatar of prashanthd
prashanthd
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial