如何从作为msi安装后任务运行的VBScript中读取64位注册表值?
在使用Visual Studio 2008部署项目创建的安装程序中,作为安装后任务的一部分,我需要从VBScript读取临时ASP.NET文件文件夹的位置 我想我会这样做:如何从作为msi安装后任务运行的VBScript中读取64位注册表值?,vbscript,64-bit,windows-installer,registry,Vbscript,64 Bit,Windows Installer,Registry,在使用Visual Studio 2008部署项目创建的安装程序中,作为安装后任务的一部分,我需要从VBScript读取临时ASP.NET文件文件夹的位置 我想我会这样做: Set oShell = CreateObject("Wscript.Shell") strPath = oShell.RegRead("HKLM\SOFTWARE\Microsoft\ASP.NET\2.0.50727.0\Path") Const HKEY_LOCAL_MACHINE = &H80000002
Set oShell = CreateObject("Wscript.Shell")
strPath = oShell.RegRead("HKLM\SOFTWARE\Microsoft\ASP.NET\2.0.50727.0\Path")
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
然后将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位注册表,如下所示:
Set oShell = CreateObject("Wscript.Shell")
strPath = oShell.RegRead("HKLM\SOFTWARE\Microsoft\ASP.NET\2.0.50727.0\Path")
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位操作系统,因此无法验证此示例是否有效。小心臭虫:-)
有关此主题的更多信息,请参见MSDN文章。我想是这样的,但我还没有整理出如何处理输出值
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
请检查以下内容:
设置oShell=CreateObject(“Wscript.Shell”)
strPath=oShell.regrad(“HKLM64\SOFTWARE\Microsoft\ASP.NET\2.0.50727.0\Path”)
使用微软有案可查的方法,海伦的答案绝对正确 然而,根据我自己的测试,仅在与StdRegProv提供程序建立连接时指定
\uu提供程序架构上下文标志就足够了。
这使得事情变得更简单,因为只需将提供程序的设置封装在单独的函数中,否则就可以使用常规API
set reg64 = MakeRegLocator(64)
reg64.GetStringValue , "SOFTWARE\Microsoft\ASP.NET\2.0.50727.0", "Path", path
WScript.Echo path
' Establish a connection to the local 32 or 64 bit registry hive as requested.
' Parameters:
' RegType - The registry bitness: 32 or 64.
function MakeRegLocator(bitness)
set ctx = CreateObject("WbemScripting.SWbemNamedValueSet")
ctx.Add "__ProviderArchitecture", bitness
set locator = CreateObject("Wbemscripting.SWbemLocator")
set services = locator.ConnectServer("", "root\default", "", "", , , , ctx)
set reg = services.Get("StdRegProv")
set MakeRegLocator = reg
end function
如何做到这一点,但只验证一个键,而不是一个值??(例如:查看是否存在“SOFTWARE\Microsoft\ASP.NET\2.0.50727.0”,但不存在“Path”value@DaniellePaquette-哈维:您需要调用而不是GetStringValue
(使用适当的参数)并检查oOutParams.ReturnValue
是否为0。此外,请参阅此问题的答案:@DaniellePaquette Harvey或者您可以查询标准值oReg.GetStringValue,“SOFTWARE\Microsoft\ASP.NET\2.0.50727.0”,stdv
,然后检查IsNull(stdv)
。受AutoIt脚本启发的技术不是VBScript,而是不同的功能