2013-01-04 70 views
13

我们使用以下函数来获取当前引导配置指定的处理器数量。这个数字纯粹用于记录。无法使用WMI读取Windows 2012 Server上的BCDStore信息

下面的函数在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。谷歌并没有发现什么有意义的与此相关的错误代码:(

堆栈跟踪说,异常在System.Win.ComObj.DispatchInvokeError这是由这是由VarDispInvoke称为DispatchInvoke称为触发。

所有这一切都是用XE2复制。我会尽量重复使用XE3问题,但我不相信德尔福RTL有什么关系呢。

有谁有关于这种行为的原因可能什么想法?

+0

你有更新4修补程序1吗? –

+0

是的,我应该有。我会仔细检查。 (exe是建立在*应该安装有U4H1的构建服务器上的。) – gabr

+0

UAC是打开还是关闭?过程升高还是不升高? –

回答

1

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元素。