WMI--Windows API--IWbemClassObject.Get

150 篇文章 0 订阅
18 篇文章 0 订阅

原文来自MSDN Library for Visual Studio 2008 SP1,翻译部分仅为个人观点,想要看更多信息请看MSDN,如有版权问题请联系QQ 643166601,邮件643166601@qq.com

Get Method of the IWbemClassObject Interface
The IWbemClassObject::Get method retrieves the specified property value, if it exists.
如果它存在,这个IWbemClassObject::Get方法取得指定属性值。
This method can also return system properties.
这个方法也可以返回系统属性。
HRESULT Get(
  [in]                 LPCWSTR wszName,
  [in]                 LONG lFlags,
  [out]                VARIANT* pVal,
  [out, optional]      CIMTYPE* pvtType,
  [out, optional]      LONG* plFlavor
);

Parameters
wszName
Name of the desired property.
想得到的属性的名称。
It is treated as read-only.
它被处理成只读。
lFlags
Reserved. This parameter must be 0 (zero).
被保留的,这个参数必须是0。
pVal
When successful, this parameter is assigned the correct type and value for the qualifier, and the VariantInit function is called on pVal.
当成功是,这个参数被赋值为正确的类型和限定的值并且在pVal上调用VariantInit。
It is the responsibility of the caller to call VariantClear on pVal when the value is not needed.
当这个值不再需要时,它是需要调用者负责任的在pVal上调用VariantClear的。
If there is an error, the value that pVal points to is not modified.
如果有一个错误,这个值pVal位置不能被修改。
If an uninitialized pVal value is passed to the method, then the caller must check the return value of the method, and call VariantClear only when the method succeeds.
如果一个未初始化的pVal值传入这个方法,那么调用者必须检查这个方法的返回值,并且只有方法成功时调用VariantClear。
pvtType
Can be NULL.
可以是NULL。
If it is not NULL, it receives the CIM type of the property, that is, one of the CIM-type constants, such as CIM_SINT32, CIM_STRING, and so on.
如果不是NULL,它接收CIM类型的属性,也就是说,CIM-type常量中的中的一个,像CIM_SINT32, CIM_STRING等等。
For more information about these values, see CIMTYPE_ENUMERATION.
更多信息关于这些值,请看CIMTYPE_ENUMERATION。
This indicates the CIM semantics of the property value packed into VARIANT.
这指示CIM语义的属性值包装到VARIANT中。
plFlavor
Can be NULL.
可以是NULL。
If not NULL, the LONG value pointed to receives information about the origin of the property.
如果不是NULL,这个LONG值指向返回的信息有关于属性的来源源。
Value Meaning
WBEM_FLAVOR_ORIGIN_SYSTEM
 The property is a standard system property.
 这个属性是一个标准的系统属性。
WBEM_FLAVOR_ORIGIN_PROPAGATED
 For classes only.
 只对于类。
 The property was inherited from the parent class.
 这个属性继承来自父类。
WBEM_FLAVOR_ORIGIN_LOCAL
 For classes only.
 只对于类。
 The property belongs to the derived child class.
 这个属性属于派生的子类。
WBEM_FLAVOR_ORIGIN_PROPAGATED
 For instances only.
 只对于实例。
 The property is inherited from the parent class, but has not been modified at the instance level.
 这个属性继承自父类,但是在实例级别没有被修改。
WBEM_FLAVOR_ORIGIN_LOCAL
 For instances only.
 只对于实例。
 The property is modified at the instance level—that is, a value was supplied, or a qualifier was added or modified.
 这个属性在实例级别被修改,也就是说,提供一个值或一个限定被增加或修改。

Return Value
This method returns an HRESULT that indicates the status of the method call.
这个方法返回一个HRESULT指示方法调用的状态。
The following table lists the value contained in an HRESULT.
一个HRESULT值包含在以下列表中。
Return code Description
WBEM_E_FAILED
 There is a general failure.
 是一个普通的失败。
WBEM_E_INVALID_PARAMETER
 One or more parameters is not valid.
 一个或更多参数是无效的。
WBEM_S_NO_ERROR
 The call succeeds.
 调用成功。
WBEM_E_NOT_FOUND
 The specified property is not found.
 这个指定的属性没有找到。
WBEM_E_OUT_OF_MEMORY
 There is not enough memory to complete the operation.
 没有足够的内存去完成操作。

Remarks
If the type of the property is an object path, date/time string, or other special type, then the returned values in the VARIANT do not contain enough information to identify the true type.
如果属性的类型是一个对象路径,日期/时间字符串,或其他指定类型,那时在VARIANT中的返回值不能包含足够地信息去识别真正的类型。
The pvtType out parameter indicates this.
这个pvtType 输出参数指示它。
To obtain the string form of the Common Information Model (CIM) type for the property, the IWbemQualifierSet pointer for the property must be obtained, and the Cimtype qualifier retrieved.
去获得公共信息模型(CIM)类型的属性的字符串形式,必须获得IWbemQualifierSet指针,并且取回限定符的Cimtype。
That qualifier is the string form of the CIM type, such as sint32 versus CIM_SINT32, which is a numeric constant.
这个限定符是一个字符串形式的CIM类型,像sint32与CIM_SINT32相对应,这是一个数字常量。
Note  When you create a new object using IWbemClassObject::SpawnInstance, it is important to note that some system properties are not set until the object is written to Windows Management Instrumentation (WMI).
注意 当你使用IWbemClassObject::SpawnInstance创建一个新的对象时,它是重要的注意一些系统属性,直到对象写入Windows管理规范(WMI)也没有设置。
In all cases, IWbemClassObject::Get succeeds in accessing the requested system property, but the returned VARIANT may contain VT_NULL.
在所有情况下,IWbemClassObject::Get成功访问这个请求系统属性,但是返回的VARIANT可能包含VT_NULL。
Example Code
The following C++ example shows how to retrieve the CIM class name from an object by using the system property __CLASS.
以下的例子演示如何从一个对象中通过使用系统属性__CLASS取回CIM类名。
The code requires the following #include statements and references to compile.
该代码需要以下#include声明和引用来编译。
#include <iostream>
using namespace std;
#include <wbemidl.h>
#pragma comment(lib, "wbemuuid.lib")
//Assumes that pObj is defined as a pointer
// to an IWbemClassObject object.

VARIANT v;
BSTR strClassProp = SysAllocString(L"__CLASS");
HRESULT hr;
hr = pObj->Get(strClassProp, 0, &v, 0, 0);
SysFreeString(strClassProp);

// check the HRESULT to see if the action succeeded.

if (SUCCEEDED(hr) && (V_VT(&v) == VT_BSTR))
{
    wprintf(L"The class name is %s\n.", V_BSTR(&v));
}
else
{
    wprintf(L"Error in getting specified object\n");
}
VariantClear(&v);

 


Example Code [MOF]
For script code examples, see WMI Tasks for Scripts and Applications and the TechNet ScriptCenter Script Repository.

For C++ code examples, see WMI C++ Application Examples.

Requirements
Client
 Requires Windows Vista, Windows XP, Windows 2000 Professional, Windows NT Workstation 4.0 SP4 and later, Windows Me, Windows 98, or Windows 95.
 
Server
 Requires Windows Server 2008, Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0 SP4 and later.
 
Header
 Declared in Wbemcli.h; include Wbemidl.h.
 
Library
 Use Wbemuuid.lib.
 
DLL
 Requires Cimwin32.dll.

Requires Esscli.dll.

Requires Evntrprv.dll.

Requires Fastprox.dll.

Requires Framedyn.dll.

Requires Krnlprov.dll.

Requires Ncprov.dll.

Requires Wbemcore.dll.

Requires Wbemess.dll.

Requires Wmipiprt.dll.
 

See Also
IWbemClassObject::GetPropertyQualifierSet
WMI System Classes
WMI System Properties
WMI Qualifiers

 

Send comments about this topic to Microsoft

Build date: 8/15/2007

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值