Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
525 views
in Technique[技术] by (71.8m points)

64 bit - How do I read 64-bit Registry values from VBScript running as a an msi post-installation task?

I need to read the location of the Temporary ASP.NET Files folder 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("HKLMSOFTWAREMicrosoftASP.NET2.0.50727.0Path")

and then concatenate strPath with "Temporary ASP.NET Files" and be done with it.

On an x64 system, however, I am getting the value from the WOW6432Node (HKLMSOFTWAREWow6432NodeMicrosoftASP.NET2.0.50727.0), which gives me the 32-bit framework path (C:WindowsMicrosoft.NETFrameworkv2.0.50727), but on an x64 system, I actually want the 64-bit path, i.e. C:WindowsMicrosoft.NETFramework64v2.0.50727.

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Not sure about launching the 64-bit script host version, but you should be able to access the 64-bit registry from the 32-bit script host using the WMI StdRegProv class, like this:

Const HKEY_LOCAL_MACHINE = &H80000002
sPath = ReadRegStr (HKEY_LOCAL_MACHINE, "SOFTWAREMicrosoftASP.NET2.0.50727.0", "Path", 64)
WScript.Echo sPath

' Reads a REG_SZ value from the local computer's 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("", "rootdefault", "", "", , , , 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'm under a 32-bit OS right now, so can't verify that this example works. Beware of bugs :-)

See also the Requesting WMI Data on a 64-bit Platform MSDN article for more info on the subject.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...