A consulta WMI executada em um console Powershell produz menos resultados no modo de 32 bits do que no modo de 64 bits

1

Essa consulta gwmi -Class Win32_PerfFormattedData_NETFramework_NETCLRMemory fornece menos resultados se eu executá-lo em um console do PowerShell de 32 bits do que em um console de 64 bits. Parece que os processos em segundo plano, como serviços, são os que aparecem apenas em 64 bits. Isso não é exclusivo para o PowerShell, estou recebendo os mesmos resultados inconsistentes em C # e F #. Eu também estou recebendo o problema em algumas ferramentas de monitoramento que eu uso.

O que está acontecendo aqui? Como faço o modo de 32 bits funcionar corretamente?

    
por plmaheu 25.05.2016 / 19:02

1 resposta

3

Adotou a solução JPBlanc de esta resposta no StackOverflow

# 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_PerfFormattedData_NETFramework_NETCLRMemory"
$oQuery = New-Object System.Management.ObjectQuery ($queryString)
$oSearcher = New-Object System.Management.ManagementObjectSearcher ($mScope, $oQuery)
$oResult = $oSearcher.Get();

$oResult.Name      # only for simple check that current code snippet gives 
                   # the same results from both 32 and 64 -bit version of PowerShell

Requesting WMI Data on a 64-bit Platform

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.

Context Flags 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.
The following lists the flags and their possible values.

  • __ProviderArchitecture Integer value, either 32 or 64, that specifies the 32-bit or 64-bit version.
  • __RequiredArchitecture Boolean value used in addition to __ProviderArchitecture to force load the specified provider version. If the version is unavailable, then WMI returns the error 0x80041013, wbemErrProviderLoadFailure for Visual Basic and WBEM_E_PROVIDER_LOAD_FAILURE for C++. The default value for this flag when it is not specified is FALSE.

On a 64-bit system that has side-by-side versions of a provider, a 32-bit application or script automatically receives data from the 32-bit provider, unless these flags are supplied and indicate that the 64-bit provider data should be returned.

    
por 25.05.2016 / 22:09