Solved

Change Value in Registry not working

Posted on 2011-03-05
13
641 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:rschraeger
  • 6
  • 5
  • 2
13 Comments
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 35044664
0
 

Author Comment

by:rschraeger
ID: 35044956
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.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 35045015
Saturdays are some times slow.  If no one else helps, click on "Request Attention" above to get others to look at your question.
0
 
LVL 12

Expert Comment

by:prashanthd
ID: 35046890
Hi,

values you are trying to set are string only?
0
 
LVL 12

Expert Comment

by:prashanthd
ID: 35046912
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

0
 

Author Comment

by:rschraeger
ID: 35055696
still did not work
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 12

Expert Comment

by:prashanthd
ID: 35055909
can you give the following inside the if <condition>, to check if condition is true for any value

wscript.echo strvalue
0
 

Author Comment

by:rschraeger
ID: 35055921
I did the echo's before and the condition comes back correctly.
0
 
LVL 12

Expert Comment

by:prashanthd
ID: 35056075
You are using the following

To get value - oReg.GetExpandedStringValue

To set Value - oReg.SetStringValue

Try using oReg.SetExpandedStringValue for setting the value
0
 

Author Comment

by:rschraeger
ID: 35057341
No change after setting the  oReg.SetExpandedStringValue
0
 
LVL 12

Expert Comment

by:prashanthd
ID: 35060035
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?
0
 

Author Comment

by:rschraeger
ID: 35063303
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.
0
 
LVL 12

Accepted Solution

by:
prashanthd earned 500 total points
ID: 35065307
Windows 7 you cannot modify the registry without elevation.

Right click and hit 'run as administrator' on command prompt

Even if you are logged in with admin rights you still need to elevate in Windows 7.

Also modified the code for display error number and description to troubleshoot further
on error resume next

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
Err.Clear 
 oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,1 
 If Err.Number<> 0 Then
 	WScript.Echo Err.Number & " - " & Err.Description
 End If
 
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

0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now