我们使用以下函数来获取当前引导配置指定的处理器数量。此数字仅用于日志记录。
下面的函数在XP、Vista、7、2003和2008上运行良好。但是,它在Windows 2012 Server上失败。
// -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与它有任何关系。
有没有人知道这种行为的可能原因?
发布于 2016-04-04 20:11:32
GetElement部分:
if objWBL.GetElement($25000061, objElement) and //<-- fails here on Server 2012
(not VarIsNull(objElement))
then
Result := StrToIntDef(objElement.Integer, 0)
else
Result := 0;可以替换为EnumerateElements
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元素。
https://stackoverflow.com/questions/14159020
复制相似问题