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.
I want to change the Source file Server path location in the reg path
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)
Please log in to answer
Posted by:
anonymous_9363
13 years ago
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.
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
13 years ago
Thank you VBScab for the inputs...
I wrote the script..
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..
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
13 years ago
Posted by:
skalpa
13 years ago
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.