我在 This tutorial on MSDN 之后创建了一个本地 WMI 提供程序.我的类(class) MOF 看起来与此类似:
[dynamic, provider("CacheProvider")]
class Cache
{
[key]
String Path;
uint32 Type;
uint64 MaxSize;
uint64 Size;
boolean Enabled;
};
除 uint64 值外,所有数据均正确返回。我读过,对于 uint64 值,您实际上需要将数据作为 BSTR 提供。它确实适用于我试过的 99% 的机器。这就是我实现这一目标的方式。
v.vt = VT_BSTR;
v.bstrVal = ToLongLongString(MaxSize);
sc = (*pNewInst)->Put(L"MaxSize", 0, &v, 0);
VariantClear(&v);
ToLongLongString
函数如下所示。
bstr_t ToLongLongString(LONGLONG llValue)
{
wchar_t szValue[21];
SecureZeroMemory(szValue, sizeof(szValue));
swprintf_s(szValue, L"%lld", llValue);
bstr_t bstrFormat(szValue);
return bstrFormat;
}
我已验证此函数返回的字符串格式正确。看起来无论出于何种原因,它都没有通过 WMI 系统。我唯一没有看到它工作的机器是 2012 R2 服务器。
最佳答案
从这里开始: http://msdn.microsoft.com/en-us/library/aa393262(v=vs.85).aspx
Note When querying for property values with a uint64 or sint64 data type in a scripting language like VBScript, WMI returns string values. Unexpected results can occur when comparing these values, because comparing strings returns different results than comparing numbers. For example, "10000000000" is less than "9" when comparing strings, and 9 is less than 10000000000 when comparing numbers. To avoid confusion you should use the CDbl method in VBScript when properties of type uint64 or sint64 are retrieved from WMI.
你可以尝试使用 CDBL 吗?
关于c++ - native WMI 提供程序中的 UINT64 不会在某些系统上返回数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20427449/