首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用WMI读取Windows2012服务器上的BCDStore信息

无法使用WMI读取Windows2012服务器上的BCDStore信息
EN

Stack Overflow用户
提问于 2013-01-04 22:29:40
回答 1查看 856关注 0票数 15

我们使用以下函数来获取当前引导配置指定的处理器数量。此数字仅用于日志记录。

下面的函数在XP、Vista、7、2003和2008上运行良好。但是,它在Windows 2012 Server上失败。

代码语言:javascript
复制
// -1 = not implemented or not allowed
//  0 = not limited
// >0 = number of processors in the {current} boot entry
function Internal_GetBCDNumberOfProcessors: integer;
var
  objBcdStore  : OleVariant;
  objElement   : OleVariant;
  objWBL       : OleVariant;
  objWMIService: OleVariant;
begin
  // for more info, see: http://stackoverflow.com/questions/7517965/accessing-bcdstore-from-delphi/7527164#7527164
  Result := -1;
  try
    objWMIService := GetObject('winmgmts:{(Backup,Restore)}\\.\root\wmi:BcdStore');
    if (not VarIsNull(objWMIService)) and
       boolean(objWMIService.OpenStore('', objBcdStore)) and
       (not VarIsNull(objBcdStore)) and
       boolean(objBcdStore.OpenObject('{fa926493-6f1c-4193-a414-58f0b2456d1e}', objWBL)) and
       (not VarIsNull(objWBL))
    then
      if objWBL.GetElement($25000061, objElement) and //<-- fails here on Server 2012
         (not VarIsNull(objElement))
      then
        Result := StrToIntDef(objElement.Integer, 0)
      else
        Result := 0;
  except
    on E: EOleSysError do
      Result := -1;
  end;
end;

如果我尝试在Win2012上运行它,objWBL.GetElement会引发EOleSysError异常,并显示文本OLE error D0000225。Google找不到任何与此错误代码相关的有意义的代码:(

堆栈跟踪说明异常是在由DispatchInvoke调用的System.Win.ComObj.DispatchInvokeError中触发的,而VarDispInvoke又调用它。

所有这些都是使用XE2重现的。我可以尝试用XE3重复这个问题,但我不认为Delphi RTL与它有任何关系。

有没有人知道这种行为的可能原因?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-04 20:11:32

GetElement部分:

代码语言:javascript
复制
if objWBL.GetElement($25000061, objElement) and //<-- fails here on Server 2012
   (not VarIsNull(objElement))
then
  Result := StrToIntDef(objElement.Integer, 0)
else
  Result := 0;

可以替换为EnumerateElements

代码语言:javascript
复制
if objWBL.EnumerateElements(objArray) then try
  for i := VarArrayLowBound(objArray, 1) to VarArrayHighBound(objArray, 1) do begin
    objElement := objArray[i];
    if objElement.Type = $25000061 then
      Exit(objElement.Integer);
  end;
finally VarClear(objArray); end;

这不会引发EOleException,但遗憾的是也找不到NumberOfProcessors元素。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14159020

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档