2013-01-04 8 views
13

Si utilizza la seguente funzione per ottenere il numero di processori specificato dalla configurazione di avvio corrente. Questo numero è utilizzato esclusivamente per la registrazione.Impossibile leggere informazioni su BCDStore su Windows 2012 Server tramite WMI

La funzione seguente funziona correttamente su XP, Vista, 7, 2003 e 2008. Tuttavia, non funziona su 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; 

Se provo a eseguire sul Win2012, l'objWBL.GetElement solleva EOleSysError eccezione con il testo OLE error D0000225. Google non trova nulla di significativo relativo a questo codice di errore :(

Stack trace dice che l'eccezione è innescato in System.Win.ComObj.DispatchInvokeError quale è invocato il DispatchInvoke che viene chiamato dal VarDispInvoke.

Tutto questo è stato riprodotto utilizzando XE2. potrei provare a ripetere il problema con XE3 ma non credo Delphi RTL ha nulla a che fare con esso.

qualcuno ha qualche idea su possibili ragioni per questo comportamento?

+0

Avete aggiornamento 1 aggiornamento rapido 1? –

+0

Sì, avrei dovuto. Controllerò due volte. (Exe è stato creato sul server di build che * dovrebbe * avere U4H1 installato.) – gabr

+0

UAC acceso o spento? Processo elevato o non elevato? –

risposta

1

La parte GetElement:

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

può essere sostituirli con 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; 

Ciò non aumentare il EOleException, ma purtroppo anche non trovare l'elemento NumberOfProcessors.

Problemi correlati