Add another source location for your MSI with VBScript

 

One downside with MSIs is the repair function. This is a challenge for all IT PROs to find a way to make the repair work when the source media is not present on the machine anymore.

While there are some alternatives to repair custom user data or registry, if you delete something important from your machine that the installer places, for example a file in C:\ProgramFiles\YourAppFolder, when you trigger a repair you will notice that you receive an error that the media could not be found.

This actually makes sense, because in theory the MSI has been removed from the installation location and those files present in the CAB are gone.

But what if you can add one or more source locations for your MSI? For example a network share.

In another post i’ve talked about how you can find the installer GUID that is placed in Classes\Installer by using the Product Code of the MSI.

In this post i extended the functionality. Not only you can find the GUID, but you can write the extra location you desire. The script will create another registry (does not replace the current one present) in HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products\YOURGUID\SourceList\Net and add the desired values.

You can add as many extra sources that you desire, when you trigger a repair, the MSI will be searched in all the locations you add.

I also made a video for this:

 

The script for this is:

 


'==========Variable Definition==========================================

Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const REG_SZ = 1
Const REG_EXPAND_SZ = 2
Const REG_BINARY = 3
Const REG_DWORD = 4
Const REG_MULTI_SZ = 7
Set WshShell = CreateObject("WScript.Shell")
strComputer = "."

'===========Add the desired product code and location===================

AddExtraLocation "{FF0355D1-4822-4CC1-9718-89C25AEC1FA9}", "C:\temp\"

'============Script functions, do not touch=============================

Function ProdReg (PC)

PC = Replace(PC,"{","")
PC = Replace(PC,"}","")
arr = Split(PC,"-")
arr1 = rev(arr(0))
arr2 = rev(arr(1))
arr3 = rev(arr(2))
arr4 = revby2(arr(3))
arr5 = revby2(arr(4))

prodreg = arr1&arr2&arr3&arr4&arr5
End Function

Function rev(s)
Dim p
For p = Len(s) To 1 Step -1
rev = rev & Mid(s, p, 1)
Next
End Function

Function revby2(str)
for x=1 to len(str)-1 step 2
v = rev(Mid(str,x,2))
revby2 = revby2 & v
next
End Function

Function CalculateSourceNr (GUID)

hDefKey = HKEY_LOCAL_MACHINE

strKeyPath = "SOFTWARE\Classes\Installer\Products\" & GUID & "\SourceList\Net"

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

strSubKeyPath = strKeyPath

oReg.EnumValues hDefKey, strSubKeyPath, arrValueNames, arrTypes

For i = LBound(arrValueNames) To UBound(arrValueNames)

strValueName = arrValueNames(i)

oReg.GetExpandedStringValue hDefKey, strSubKeyPath, strValueName, strValue

returnreg = strValueName + 1

Next

CalculateSourceNr = returnreg
End Function

Function AddExtraLocation (ProductCode,Location)

GUIDNR = ProdReg(ProductCode)

myKey = "HKLM\SOFTWARE\Classes\Installer\Products\" & GUIDNR & "\SourceList\Net\" & CalculateSourceNr (GUIDNR)
WshShell.RegWrite myKey,Location,"REG_EXPAND_SZ"

End Function

 

Or you can download it from here.

Sharing is caring!

Leave a comment

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

two × four =