2013-01-04 12 views
13

Korzystamy z poniższej funkcji, aby uzyskać liczbę procesorów określoną przez bieżącą konfigurację rozruchu. Ten numer jest używany wyłącznie do logowania.Nie można odczytać informacji BCDStore na serwerze Windows 2012 za pomocą WMI

Poniższa funkcja działa prawidłowo w systemach XP, Vista, 7, 2003 i 2008. Nie działa jednak na serwerze Windows 2012.

// -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; 

Gdy próbuję uruchomić go na Win2012 The objWBL.GetElement podnosi EOleSysError wyjątek z tekstem OLE error D0000225. Google nie znaleźć niczego sensownego związane z tym kodem błędu :(

Ślad stosu mówi, że wyjątek jest wyzwalany w System.Win.ComObj.DispatchInvokeError który jest nazywany przez DispatchInvoke który jest nazywany przez VarDispInvoke.

Wszystko to zostało odtworzone za pomocą XE2. mogłem spróbować powtórzyć problem z XE3 ale nie wierzę, Delphi RTL ma nic wspólnego z nim.

Czy ktoś ma jakiś pomysł na temat możliwych przyczyn tego zachowania?

+0

Czy masz aktualizację 4 poprawkę 1? –

+0

Tak, powinienem był. Sprawdzę dwa razy. (Exe zostało zbudowane na serwerze kompilacji, który * powinien * mieć zainstalowany U4H1.) – gabr

+0

UAC jest włączony lub wyłączony? Proces podniesiony lub nie podniesiony? –

Odpowiedz

1

Część GetElement:

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

można zastąpić 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; 

nie podnieść EOleException, ale niestety również nie znaleźć element NumberOfProcessors.

Powiązane problemy