无法从32位进程访问Win32_WinSAT

时间:2013-10-01 15:47:04

标签: powershell wmi wmi-query

从x64进程请求Win32_WinSAT时,我得到了正确的结果(WinSATAssessmentState = 1),但是当从x86执行时,我得到“结果不可用”(WinSATAssessmentState = 3)

x64 Powershell:

PS C:\Users\alive> gwmi Win32_WinSAT


__GENUS               : 2
__CLASS               : Win32_WinSAT
__SUPERCLASS          :
__DYNASTY             : Win32_WinSAT
__RELPATH             : Win32_WinSAT.TimeTaken="MostRecentAssessment"
__PROPERTY_COUNT      : 8
__DERIVATION          : {}
__SERVER              : COMPNAME
__NAMESPACE           : root\cimv2
__PATH                : \\COMPNAME\root\cimv2:Win32_WinSAT.TimeTaken="MostRecentAssessment"
CPUScore              : 7,2
D3DScore              : 6,3
DiskScore             : 7,65
GraphicsScore         : 4,6
MemoryScore           : 5,9
TimeTaken             : MostRecentAssessment
WinSATAssessmentState : 1
WinSPRLevel           : 4,6
PSComputerName        : COMPNAME

x86 Powershell

PS C:\Users\alive> gwmi Win32_WinSAT


__GENUS               : 2
__CLASS               : Win32_WinSAT
__SUPERCLASS          :
__DYNASTY             : Win32_WinSAT
__RELPATH             : Win32_WinSAT.TimeTaken="MostRecentAssessment"
__PROPERTY_COUNT      : 8
__DERIVATION          : {}
__SERVER              : COMPNAME
__NAMESPACE           : root\cimv2
__PATH                : \\COMPNAME\root\cimv2:Win32_WinSAT.TimeTaken="MostRecentAssessment"
CPUScore              : 0
D3DScore              : 0
DiskScore             : 0
GraphicsScore         : 0
MemoryScore           : 0
TimeTaken             : MostRecentAssessment
WinSATAssessmentState : 3
WinSPRLevel           : 0
PSComputerName        : COMPNAME

是否有任何标志或特殊方法可以从x86进程访问此信息?

感谢。

1 个答案:

答案 0 :(得分:2)

您的问题属于Requesting WMI Data on a 64-bit Platform

默认情况下,当存在两个版本的提供程序时,应用程序或脚本会从相应的提供程序接收数据。 32位提供程序将数据返回到32位应用程序(包括所有脚本),64位提供程序将数据返回到64位已编译的应用程序。但是,应用程序或脚本可以通过方法调用上的标志通知WMI来从非默认提供程序(如果存在)请求数据。 __ ProviderArchitecture __ RequiredArchitecture 字符串标志具有一组由WMI处理但未在SDK标头或类型库文件中定义的值。这些值放在一个上下文参数中,以通知WMI它应该从非默认提供程序请求数据。

我不知道如何使用PowerShell CmdLets,但您可以使用.NET Framework中的“System.Management”类(COM对象封装)。

# Setup the context information
$mContext = New-Object System.Management.ManagementNamedValueCollection
$mContext.Add( "__ProviderArchitecture", 64)
$mContext.Add( "__RequiredArchitecture", $true)

# Setup the Authrntification object
$ConOptions = New-Object System.Management.ConnectionOptions
#$ConOptions.Username = "computername\administrateur" # Should be used for remote access
#$ConOptions.Password = "toto"
$ConOptions.EnablePrivileges = $true
$ConOptions.Impersonation = "Impersonate"
$ConOptions.Authentication = "Default"
$ConOptions.Context = $mContext

# Setup the management scope (change with the computer name for remote access)
$mScope = New-Object System.Management.ManagementScope("\\localhost\root\cimV2", $ConOptions)

$mScope.Connect()

# Query
$queryString = "SELECT * From Win32_WinSAT"
$oQuery = New-Object System.Management.ObjectQuery ($queryString)
$oSearcher = New-Object System.Management.ManagementObjectSearcher ($mScope, $oQuery)
$oSearcher.Get();

我在Windows 8中从32位和64位PowerShell执行此脚本bith,两者都有效。

相关问题