A MS-DOS script executes the VBScript below and it works fine. However, when using a MS Build master deployment file which calls the aforementioned MS-DOS script, the 2nd location lookup ("SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\") fails with a result code of 2. I have spent countless hours trying to figure out why the difference. Any ideas?
Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
Set oRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & node & "/root/default:StdRegProv")
REM 1st location: "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
sBaseKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
iRC = oRegistry.EnumKey(HKLM, sBaseKey, arSubKeys)
If iRC <> 0 THEN
WScript.Echo "Registry lookup failed for " & sBaseKey
ELSE
For Each sKey In arSubKeys
iRC = oRegistry.GetStringValue(HKLM, sBaseKey & sKey, "DisplayName", sValue)
If sValue = Wscript.Arguments.Item(1) Then
oRegistry.GetStringValue HKLM, sBaseKey & sKey, "UninstallString", sValue
InstalledApplications = Replace(sValue, "/I{", "/X{")
IF LEN(InstalledApplications) > 0 THEN
InstalledApplications = InstalledApplications & " /qn /l*vx """ & sFile & ".Log""" & Chr(13) & Chr(10)
END IF
END IF
NEXT
END IF
REM 2nd location: "SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\<GUID>\InstallProperties"
arProducts = NULL
sBaseKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\"
iRC = oRegistry.EnumKey(HKLM, sBaseKey, arProducts)
If iRC <> 0 THEN
WScript.Echo "Registry lookup failed for " & sBaseKey
ELSE
For Each guid In arProducts
sInnerKey = sBaseKey & guid & "\InstallProperties\"
iRC = oRegistry.GetStringValue(HKLM, sInnerKey, "DisplayName", sValue)
If sValue = Wscript.Arguments.Item(1) Then
oRegistry.GetStringValue HKLM, sInnerKey, "UninstallString", sValue
InstalledApplications = Replace(sValue, "/I{", "/X{")
IF LEN(InstalledApplications) > 0 THEN
InstalledApplications = InstalledApplications & " /qn /l*vx """ & sFile & ".Log""" & Chr(13) & Chr(10)
END IF
END IF
NEXT
InstalledApplications = InstalledApplications & "GOTO:EOF"