2013-01-04 44 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元素。