How to read 64-bit registry values ​​from VBScript executed as msi post-installation task?

I need to read the folder location of ASP.NET temporary files from VBScript as part of a post-installation task in an installer created using a Visual Studio 2008 deployment project.

I thought I would do something like this:

Set oShell = CreateObject("Wscript.Shell")
strPath = oShell.RegRead("HKLM\SOFTWARE\Microsoft\ASP.NET\2.0.50727.0\Path")

and then connect strPath with "\ Temporary ASP.NET Files" and do with it.

However, on an x64 system, I get the value from WOW6432Node (HKLM \ SOFTWARE \ Wow6432Node \ Microsoft \ ASP.NET \ 2.0.50727.0), which gives me a 32-bit framework path (C: \ Windows \ Microsoft.NET \ Framework \ v2. 0.50727), but on an x64 system I really need a 64-bit path, i.e. C: \ Windows \ Microsoft.NET \ Framework64 \ v2.0.50727.

I understand that this is because the .vbs file is being run using the 32-bit host script because the parent process (installer) is 32-bit.

How can I run a script using a 64-bit script host - or - how can I read 64-bit values, even if the script is executed using a 32-bit script host?

+5
source share
3 answers

Not sure if the 64-bit version of the host script will be launched, but you should have access to the 64-bit registry from the 32-bit host script using WMI StdRegProv, for example:

Const HKEY_LOCAL_MACHINE = &H80000002
sPath = ReadRegStr (HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\ASP.NET\2.0.50727.0", "Path", 64)
WScript.Echo sPath

' Reads a REG_SZ value from the local computer registry using WMI.
' Parameters:
'   RootKey - The registry hive (see http://msdn.microsoft.com/en-us/library/aa390788(VS.85).aspx for a list of possible values).
'   Key - The key that contains the desired value.
'   Value - The value that you want to get.
'   RegType - The registry bitness: 32 or 64.
'
Function ReadRegStr (RootKey, Key, Value, RegType)
    Dim oCtx, oLocator, oReg, oInParams, oOutParams

    Set oCtx = CreateObject("WbemScripting.SWbemNamedValueSet")
    oCtx.Add "__ProviderArchitecture", RegType

    Set oLocator = CreateObject("Wbemscripting.SWbemLocator")
    Set oReg = oLocator.ConnectServer("", "root\default", "", "", , , , oCtx).Get("StdRegProv")

    Set oInParams = oReg.Methods_("GetStringValue").InParameters
    oInParams.hDefKey = RootKey
    oInParams.sSubKeyName = Key
    oInParams.sValueName = Value

    Set oOutParams = oReg.ExecMethod_("GetStringValue", oInParams, , oCtx)

    ReadRegStr = oOutParams.sValue
End Function

NB: I am now on a 32-bit OS, so I can’t check if this example works. Beware of mistakes :-)

. WMI 64- . MSDN .

+6

, - , , .

strComputer = "."
Const HKLM = &h80000002
Set objCtx = CreateObject("WbemScripting.SWbemNamedValueSet")
objCtx.Add "__ProviderArchitecture", 64
objCtx.Add "__RequiredArchitecture", TRUE
Set objLocator = CreateObject("Wbemscripting.SWbemLocator")
Set objServices = objLocator.ConnectServer("","root\default","","",,,,objCtx)
Set objStdRegProv = objServices.Get("StdRegProv") 

' Use ExecMethod to call the GetStringValue method
Set Inparams = objStdRegProv.Methods_("EnumValues").Inparameters
Inparams.Hdefkey = HKLM
Inparams.Ssubkeyname = "SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL\"
'Inparams.Svaluename = "Logging"
set Outparams = objStdRegProv.ExecMethod_("EnumValues", Inparams,,objCtx)

'Show output parameters object and the registry value HKLM\SOFTWARE\
WScript.Echo Outparams.GetObjectText_
WScript.Echo "WMI Logging is set to  " & Outparams.SValue
0

, :

oShell = CreateObject ( "Wscript.Shell" ) strPath = oShell.RegRead( "HKLM64\SOFTWARE\Microsoft\ASP.NET\2.0.50727.0\Path" )

https://www.autoitscript.com/autoit3/docs/functions/RegRead.htm

-1

All Articles