无法从 32 位进程访问 Win32_WinSAT [英] Cannot access Win32_WinSAT from 32 bits process

查看:47
本文介绍了无法从 32 位进程访问 Win32_WinSAT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When requesting Win32_WinSAT from a x64 process I get the correct results (WinSATAssessmentState = 1), but when executed from a x86 I get "results not available" (WinSATAssessmentState = 3)

x64 Powershell:

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

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 进程访问此信息?

Is there any flag or special method to be able to access this information from the x86 process?

谢谢.

推荐答案

您的问题属于 在 64 位平台上请求 WMI 数据.

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

By default, an application or script receives data from the corresponding provider when two versions of providers exist. The 32-bit provider returns data to a 32-bit application, including all scripts, and the 64-bit provider returns data to the 64-bit compiled applications. However, an application or script can request data from the nondefault provider, if it exists, by notifying WMI through flags on method calls. The __ProviderArchitecture and __RequiredArchitecture string flags have a set of values handled by WMI but not defined in SDK header or type library files. The values are placed in a context parameter to signal WMI that it should request data from the nondefault provider.

我不知道如何使用 PowerShell CmdLets 执行此操作,但您可以使用 .NET Framework 中的System.Management"类(COM 对象封装).

I don't know how to do that with PowerShell CmdLets, but you can use "System.Management" classes from the .NET Framework (COM object encapsulation).

# 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 执行此脚本,并且两者都有效.

I execute this script bith from 32 and 64 bits PowerShell in Windows 8 and both works.

这篇关于无法从 32 位进程访问 Win32_WinSAT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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