使用WMI无法在Windows 2012 Server上读取BCDStore信息

前端之家收集整理的这篇文章主要介绍了使用WMI无法在Windows 2012 Server上读取BCDStore信息前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我们使用以下函数获取当前引导配置指定的处理器数量.这个数字纯粹用于记录.

以下功能在XP,Vista,7,2003和2008上可以正常工作,但在Windows 2012 Server上失败.

  1. // -1 = not implemented or not allowed
  2. // 0 = not limited
  3. // >0 = number of processors in the {current} boot entry
  4. function Internal_GetBCDNumberOfProcessors: integer;
  5. var
  6. objBcdStore : OleVariant;
  7. objElement : OleVariant;
  8. objWBL : OleVariant;
  9. objWMIService: OleVariant;
  10. begin
  11. // for more info,see: https://stackoverflow.com/questions/7517965/accessing-bcdstore-from-delphi/7527164#7527164
  12. Result := -1;
  13. try
  14. objWMIService := GetObject('winmgmts:{(Backup,Restore)}\\.\root\wmi:BcdStore');
  15. if (not VarIsNull(objWMIService)) and
  16. boolean(objWMIService.OpenStore('',objBcdStore)) and
  17. (not VarIsNull(objBcdStore)) and
  18. boolean(objBcdStore.OpenObject('{fa926493-6f1c-4193-a414-58f0b2456d1e}',objWBL)) and
  19. (not VarIsNull(objWBL))
  20. then
  21. if objWBL.GetElement($25000061,objElement) and //<-- fails here on Server 2012
  22. (not VarIsNull(objElement))
  23. then
  24. Result := StrToIntDef(objElement.Integer,0)
  25. else
  26. Result := 0;
  27. except
  28. on E: EOleSysError do
  29. Result := -1;
  30. end;
  31. end;

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

堆栈跟踪表示异常在System.Win.ComObj.DispatchInvokeError中被触发,由DispatchInvoke调用,由VarDispInvoke调用.

所有这些都是使用XE2进行复制的.我可以尝试重复XE3的问题,但我不相信Delphi RTL与它有任何关系.

有谁有任何想法可能的原因这种行为?

GetElement部分:
  1. if objWBL.GetElement($25000061,objElement) and //<-- fails here on Server 2012
  2. (not VarIsNull(objElement))
  3. then
  4. Result := StrToIntDef(objElement.Integer,0)
  5. else
  6. Result := 0;

可以用EnumerateElements替换:

  1. if objWBL.EnumerateElements(objArray) then try
  2. for i := VarArrayLowBound(objArray,1) to VarArrayHighBound(objArray,1) do begin
  3. objElement := objArray[i];
  4. if objElement.Type = $25000061 then
  5. Exit(objElement.Integer);
  6. end;
  7. finally VarClear(objArray); end;

这不会引发EOleException,但是遗憾的是还没有找到NumberOfProcessors元素.

猜你在找的Windows相关文章