Replace installer source path in registry

Usage:
Script runs locally on computer to replace installer source paths for installed software in the registry. Most likely usable if you migrate your DFS or file server when the path to the package changes.

Script does both current user and root hive.


' START COPY HERE

' EDIT HERE
RegSearchFind = "OLDFDSicadfsGpoAppsPKGs"
RegSearchReplace = "NEWDFStestdfsjajamensan"
' DO NOT CHANGE BELOW
Const HKEY_CLASSES_ROOT = &H80000000
strComputer = "."
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!" & strComputer & "rootdefault:StdRegProv")
strRootKeyPath = "InstallerProducts"
objReg.EnumKey HKEY_CLASSES_ROOT, strRootKeyPath, arrSubKeys
For Each objSubKey In arrSubKeys
strKeyPath = strRootKeyPath & "" & objSubkey & "" & "SourceList"
strValueName = "LastUsedSource"
objReg.GetExpandedStringValue HKEY_CLASSES_ROOT,strKeyPath,strValueName,strValue
If INSTR(strvalue, RegSearchFind) <> 0 Then
strValue = Replace(strValue, RegSearchFind, RegSearchReplace)
objReg.SetExpandedStringValue HKEY_CLASSES_ROOT,strKeyPath,strValueName,strValue
Else
End If
Next

Set objReg = Nothing

Const HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!" & strComputer & "rootdefault:StdRegProv")
strRootKeyPath = "SoftwareMicrosoftInstallerProducts"
objReg.EnumKey HKEY_CURRENT_USER, strRootKeyPath, arrSubKeys
For Each objSubKey In arrSubKeys
strKeyPath = strRootKeyPath & "" & objSubkey & "" & "SourceList"
strValueName = "LastUsedSource"
wscript.echo strKeyPath
objReg.GetExpandedStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue
If INSTR(strvalue, RegSearchFind) <> 0 Then
strValue = Replace(strValue, RegSearchFind, RegSearchReplace)
objReg.SetExpandedStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue
Else
End If
Next
' END COPY HERE - SAVE AS VBS

Leave a Reply

Your email address will not be published. Required fields are marked *