gpt4 book ai didi

vbscript - 如何从作为 msi 安装后任务运行的 VBScript 读取 64 位注册表值?

转载 作者:行者123 更新时间:2023-12-04 11:46:05 25 4
gpt4 key购买 nike

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

我以为我会做这样的事情:

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

然后将 strPath 与 "\Temporary ASP.NET Files"连接起来并完成它。

但是,在 x64 系统上,我从 WOW6432Node (HKLM\SOFTWARE\Wow6432Node\Microsoft\ASP.NET\2.0.50727.0) 获取值,它为我提供了 32 位框架路径 (C:\Windows\Microsoft. NET\Framework\v2.0.50727),但在 x64 系统上,我实际上想要 64 位路径,即 C:\Windows\Microsoft.NET\Framework64\v2.0.50727。

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

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

最佳答案

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

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'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("", "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

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

另见 Requesting WMI Data on a 64-bit Platform有关该主题的更多信息,请参阅 MSDN 文章。

关于vbscript - 如何从作为 msi 安装后任务运行的 VBScript 读取 64 位注册表值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1229760/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com