/build/static/layout/Breadcrumb_cap_w.png

vbscript to read registry keys and its subkeys

Hello All,

I want to change the Source file Server path location in the reg path HKEY_CLASSES_ROOT\Installer\Products\Product GUID\SourceList\Net\1 of every client machines, as we have removed the existing Application server with a new one...We were able to change the old server path to new server path using the "replace" function in vbscript. Set objWS = CreateObject("WScript.Shell")

strKeyValue = objWS.RegRead("HKEY_CLASSES_ROOT\Installer\Products\A7C4EB2D0BDDF2A43BDD35A498E12655\SourceList\Net\1")

newstrKeyValue = Replace(strKeyValue,"\\INADCSRV11" ,"\\INADCSRV12")

newstrKeyValue2 = Replace (newstrKeyValue ,"SMSPKGC$" ,"SMSPKGP$")


Const HKEY_CLASSES_ROOT = &H80000000
strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")

strKeyPath = "Installer\Products\A7C4EB2D0BDDF2A43BDD35A498E12655\SourceList\Net\"
strValueName = "1"
strValue = newstrKeyValue2

oReg.SetExpandedStringValue HKEY_CLASSES_ROOT,strKeyPath,strValueName,strValue
but we are stuck in reading the reg values.... Product GUID is a variable.First we have to read till that path and then after reading one GUID, again we have to read the complete path HKEY_CLASSES_ROOT\Installer\Products\<Product GUID>\SourceList\Net\1 and then change the server name Please let me know anyone have encountered any situation like this.

0 Comments   [ + ] Show comments

Answers (4)

Posted by: anonymous_9363 12 years ago
Red Belt
0
Firstly, I hope now you can see why people use DNS aliases for things like deployment servers?

Secondly, which part are you having problems with? How to loop through the keys or mangling the GUID to its "compressed" form? Either way, solutions have been posted here many times.

For reading the keys, their values and data, check out the registry class which is part of the JSWare class pack (actually, I think I've posted the entire script here before). It has functions EnumKeys and EnumValuesAndData (or similar names).

For mangling and unmangling GUIDs, searching my posts for the word "munge" should turn up 2 functions for that.
Posted by: anphi 12 years ago
Orange Belt
0
Thank you VBScab for the inputs...

I wrote the script..



On error resume next
Const HKEY_CLASS_ROOT = &H80000000

strComputer = "."
strKeyPath = "Installer\Products"

Set objShell = CreateObject("WScript.Shell")
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

oReg.EnumKey HKEY_CLASS_ROOT, strKeyPath, arrSubkeys

If IsArray(arrSubkeys) Then
For Each strSubkey In arrSubkeys

strkeyvalue = objShell.regread ("HKEY_CLASSES_ROOT\Installer\Products\" & strSubkey & "\SourceList\Net\1")

strKeySuffix = Left(strkeyvalue, 12)

if strKeySuffix = "\\DCASRV11" then

newstrKeyValue = Replace (strkeyvalue, "\\DCASRV11", "\\DCASRV12")

newstrKeyValue2 = Replace (newstrKeyValue ,"SMSPKGC$" ,"SMSPKGP$")



strKeyPath = "Installer\Products\" & strSubkey & "\SourceList\Net\"
strValueName = "1"
strValue = newstrKeyValue2

oReg.SetExpandedStringValue HKEY_CLASSES_ROOT,strKeyPath,strValueName,strValue


End if
Next
End If



But the probelm is it is not overwriting the existing value. If I run the vbs after removing the array part(tried with one GUID) it is overwriting the Value..

I think the issue is with the "oReg.SetExpandedStringValue HKEY_CLASSES_ROOT,strKeyPath,strValueName,strValue"



Any thoughts on this..

Comments:
  • Hello,
    I need to do the same thing and wanted to know if you where able to get a working script?
    =Matt - swallmx 12 years ago
Posted by: anonymous_9363 12 years ago
Red Belt
0
Install a script debugger. At the very least, try the Microsoft Script Debugger but better, if you install Visual Studio Express Edition, use that. You can then 'Debug.Print [variable_name]' or 'Debug.Print err.number' and so on.
Posted by: skalpa 12 years ago
Senior Yellow Belt
0
Did you try this ? [:)]

Dim objInstaller
Set objInstaller = CreateObject("WindowsInstaller.Installer")
objInstaller.AddSource "{YOURAPPLICATIONGUID}", "", "\\NEWSERVER\Path"



[/align]
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ