Registry's EnumKey Lookup Failing When Called By MSBuild?

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"

February 23rd, 2015 8:52am

64/32 bit execution environments.  Default build for VS is 32 bit.

You need to ask this kind of question in the developers forum.

Free Windows Admin Tool Kit Click here and download it now
February 23rd, 2015 9:16am

64/32 bit execution environments.  Default build for VS is 32 bit.

You need to ask this kind of question in the developers forum.

February 23rd, 2015 10:06am

Depends on how you are executing MSBuild.

Again - this is a question for the developer forum.  It is not a scripting issue as you have already proven that the script works.

Free Windows Admin Tool Kit Click here and download it now
February 23rd, 2015 10:20am

Think about the issue. What does returncode 2 mean and why might you get it.  Either the path does not exist or you are looking at the wrong registry view.

Try this:

c:\windows\system32\cscript <yourscript>

and

c:\windows\SysWow64\cscript <yourscript>

One should succeed and the other fail.

February 23rd, 2015 10:24am

Think about the issue. What does returncode 2 mean and why might you get it.  Either the path does not exist or you are looking at the wrong registry view.

Try this:

c:\windows\system32\cscript <yourscript>

and

c:\windows\SysWow64\cscript <yourscript>

One should succeed and the other fail.

Free Windows Admin Tool Kit Click here and download it now
February 23rd, 2015 2:31pm

There is no DOS. Cmd.exe is a Win32 console program that, despite appearances, has nothing whatsoever to do with DOS.

February 23rd, 2015 3:17pm

Think about the issue. What does returncode 2 mean and why might you get it.  Either the path does not exist or you are looking at the wrong registry view.

Try this:

c:\windows\system32\cscript <yourscript>

and

c:\windows\SysWow64\cscript <yourscript>

One should succeed and the other fail.

Free Windows Admin Tool Kit Click here and download it now
February 23rd, 2015 3:21pm

Think about the issue. What does returncode 2 mean and why might you get it.  Either the path does not exist or you are looking at the wrong registry view.

Try this:

c:\windows\system32\cscript <yourscript>

and

c:\windows\SysWow64\cscript <yourscript>

One should succeed and the other fail.

February 24th, 2015 10:44am

Those keys are not visible form the 32 bit version of MSBuild and Visual Studio,  You must run from a 64 bit session to access the 64 bit registry.  Change your build environment to 64 bits and try it.

Free Windows Admin Tool Kit Click here and download it now
February 24th, 2015 11:05am

Or try sysnative:

https://msdn.microsoft.com/en-us/library/windows/desktop/aa384187%28v=vs.85%29.aspx

February 24th, 2015 11:23am

Now that you recognize the symptom you will not get easily caught by this.  The first time is a bit of a hassle.
Free Windows Admin Tool Kit Click here and download it now
February 24th, 2015 12:17pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics