Solved

Change Value in Registry not working

Posted on 2011-03-05
13
648 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 2
13 Comments
 
LVL 83

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 83

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

734 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