如何从作为 msi 安装后任务运行的 VBScript 读取 64 位注册表值? [英] How do I read 64-bit Registry values from VBScript running as a an msi post-installation task?

查看:18
本文介绍了如何从作为 msi 安装后任务运行的 VBScript 读取 64 位注册表值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为使用 Visual Studio 2008 部署项目创建的安装程序中的安装后任务的一部分,我需要从 VBScript 读取 Temporary ASP.NET Files 文件夹的位置.

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")

然后将 strPath 与Temporary ASP.NET Files"连接起来就可以了.

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

但是,在 x64 系统上,我从 WOW6432Node (HKLMSOFTWAREWow6432NodeMicrosoftASP.NET2.0.50727.0) 获取值,它为我提供了 32 位框架路径 (C:WindowsMicrosoft.NETFrameworkv2.0.50727),但在 x64 系统上,我实际上想要 64 位路径,即 C:WindowsMicrosoft.NETFramework64v2.0.50727.

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.

我知道发生这种情况是因为 .vbs 文件使用 32 位脚本主机运行,因为父进程(安装程序)本身是 32 位.

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.

如何使用 64 位脚本主机运行脚本 - 或者 - 即使使用 32 位脚本主机运行脚本,我如何读取 64 位值?

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?

推荐答案

不确定是否启动 64 位脚本主机版本,但您应该能够使用 32 位脚本主机访问 64 位注册表WMI StdRegProv 类,像这样:

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

注意:我现在使用的是 32 位操作系统,因此无法验证此示例是否有效.当心错误:-)

另请参阅请求 WMI 数据64 位平台 MSDN 文章,了解有关该主题的更多信息.

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

这篇关于如何从作为 msi 安装后任务运行的 VBScript 读取 64 位注册表值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆