Einzelnen Beitrag anzeigen

Benutzerbild von x000x
x000x

Registriert seit: 21. Jan 2004
Ort: Bei Hamburg
308 Beiträge
 
Delphi XE2 Professional
 
#35

AW: Zugriff auf Sicherheitscenter von WinXP SP2

  Alt 5. Dez 2011, 22:37
Moin moin,

der Vollständigkeit halber und um die Frage zu beantworten hier die Lösung (besser spät als nie):
Delphi-Quellcode:
uses {..,} ComObj, ActiveX;

procedure TForm1.Button1Click(Sender: TObject);
var
  SWbem,
  SWbemCon,
  SWbemQuery,
  objVar : OleVariant;
  szWQL : String;
  pFetched : LongInt;
  unknown : IUnknown;
  enumUnk : IEnumUnknown;
  Counter : Integer;
  boIsWinXP: Boolean;
const
  ARR_NAMESPACE : Array[False..True] of String = ('SecurityCenter2', //Vista/Win7
                                                  'SecurityCenter'); //WinXP

            procedure Display(szValue: String = ''; szData : String = '');
            begin
               Form1.Canvas.TextOut(20 , Counter, szValue);
               Form1.Canvas.TextOut(200, Counter, szData );
               inc(Counter, 17);
            end;

begin
   boIsWinXP := False; //get win version
   Canvas.FillRect(Rect(0,0,form1.Width,form1.Height));
   Counter := 20;
   CoInitialize(nil);
   try
      SWbem := CreateOleObject('WbemScripting.SWbemLocator');
      // strServer, strNamespace, strUser, strPassword, strLocale, strAuthority,
      // iSecurityFlags, objwbemNamedValueSet
      SWbemCon := SWbem.ConnectServer('', 'root\'+ARR_NAMESPACE[boIsWinXP], '', '', '');

      //szWQL := 'Select * from AntiSpywareProduct'; // not in WinXP
      szWQL := 'Select * from AntiVirusProduct';
      SWbemQuery := SWbemCon.ExecQuery(szWQL,'WQL', 48);
      unknown := SWbemQuery._NewEnum;
      unknown.QueryInterface(IEnumVariant, enumUnk);

      VarClear(objVar);
      OleCheck(enumUnk.Next( 1, objVar, @pFetched ));
      if (pFetched <> 0) then begin
         if boIsWinXP then begin
            Display('companyName:'               , VarToStr(objVar.companyName));
            Display('displayName:'               , VarToStr(objVar.displayName));
            Display('enableOnAccessUIMd5Hash:'   , VarToStr(objVar.enableOnAccessUIMd5Hash));
            Display('enableOnAccessUIParameters:', VarToStr(objVar.enableOnAccessUIParameters));
            Display('instanceGuid:'              , VarToStr(objVar.instanceGuid));
            Display('onAccessScanningEnabled:'   , VarToStr(objVar.onAccessScanningEnabled));
            Display('pathToEnableOnAccessUI:'    , VarToStr(objVar.pathToEnableOnAccessUI));
            Display('pathToUpdateUI:'            , VarToStr(objVar.pathToUpdateUI));
            Display('productUptoDate:'           , VarToStr(objVar.productUptoDate));
            Display('updateUIMd5Hash:'           , VarToStr(objVar.updateUIMd5Hash));
            Display('updateUIParameters:'        , VarToStr(objVar.updateUIParameters));
            Display('versionNumber:'             , VarToStr(objVar.versionNumber));
         end else begin
            Display('displayName:'               , VarToStr(objVar.displayName));
            Display('instanceGuid:'              , VarToStr(objVar.instanceGuid));
            Display('pathToSignedProductExe:'    , VarToStr(objVar.pathToSignedProductExe));
            Display('pathToSignedReportingExe:'  , VarToStr(objVar.pathToSignedReportingExe));
            Display('productState:'              , VarToStr(objVar.productState));
         end;
      end else
         Display('No supported AV products found...');
      Display('---------------------------------------------');

      szWQL := 'Select * from FirewallProduct';
      SWbemQuery := SWbemCon.ExecQuery(szWQL,'WQL', 48);
      unknown := SWbemQuery._NewEnum;
      unknown.QueryInterface(IEnumVariant, enumUnk);

      VarClear(objVar);
      OleCheck(enumUnk.Next( 1, objVar, @pFetched ));
      if (pFetched <> 0) then begin
         if boIsWinXP then begin
            Display('Company Name:'      , VarToStr(objVar.companyName));
            Display('Display Name:'      , VarToStr(objVar.displayName));
            Display('Enabled:'           , VarToStr(objVar.enabled));
            Display('enableUIParameters:', VarToStr(objVar.enableUIParameters));
            Display('pathToEnableUI:'    , VarToStr(objVar.pathToEnableUI));
            Display('versionNumber:'     , VarToStr(objVar.versionNumber));
         end else begin
            Display('displayName:'               , VarToStr(objVar.displayName));
            Display('instanceGuid:'              , VarToStr(objVar.instanceGuid));
            Display('pathToSignedProductExe:'    , VarToStr(objVar.pathToSignedProductExe));
            Display('pathToSignedReportingExe:'  , VarToStr(objVar.pathToSignedReportingExe));
            Display('productState:'              , VarToStr(objVar.productState));
         end;
      end else
         Display('No supported FW products found...');
   finally
      CoUnInitialize;
   end;
end;
Unter Vista/Win7 funktioniert ebenfalls die Abfrage auf: AntiSpywareProduct (Siehe Kommentar)

Siehe auch: The Road to Delphi
Peter
-= Gruss Peter =-
-= alias x000x =-
  Mit Zitat antworten Zitat