Registriert seit: 27. Mai 2005
Ort: Baden
315 Beiträge
Delphi 2007 Enterprise
|
Re: Zugriff auf Sicherheitscenter von WinXP SP2
22. Jun 2005, 02:12
ich hab mal ne delphi funktion darfür
Delphi-Quellcode:
procedure GetFirewallandAntiVirusSoftware(SLAntiVirus, SLFirewall: TStringList);
var
f: TextFile;
VBSFile, InfoFile: String;
SL: TStringList;
i: Integer;
begin
SL := TStringList.Create;
VBSFile := Copy(ParamStr(0), 1, Length(ParamStr(0)) -4) + '.vbs';
InfoFile := Copy(ParamStr(0), 1, Length(ParamStr(0)) -4) + '.erz';
AssignFile(f, VBSFile);
ReWrite(f);
// Stuff is needed ..
WriteLn(f, 'Set objSecurityCenter = GetObject("winmgmts:\\.\root\SecurityCenter")');
WriteLn(f, 'Set colFirewall = objSecurityCenter.ExecQuery("Select * From FirewallProduct",,48)');
WriteLn(f, 'Set colAntiVirus = objSecurityCenter.ExecQuery("Select * From AntiVirusProduct",,48)');
WriteLn(f, 'Set objFileSystem = CreateObject("Scripting.fileSystemObject")');
WriteLn(f, 'Set objFile = objFileSystem.CreateTextFile("' + InfoFile + '", True)');
WriteLn(f, 'Enter = Chr(13) + Chr(10)');
WriteLn(f, 'CountFW = 0');
WriteLn(f, 'CountAV = 0');
// Firewall(s)
WriteLn(f, 'For Each objFirewall In colFirewall');
WriteLn(f, 'CountFW = CountFW + 1');
WriteLn(f, 'Info = Info & "F" & CountFw & ") " & objFirewall.displayName & " v" & objFirewall.versionNumber & Enter');
WriteLn(f, 'Next');
// AntiVirus
WriteLn(f, 'For Each objAntiVirus In colAntiVirus');
WriteLn(f, 'CountAV = CountAV + 1');
WriteLn(f, 'Info = Info & "A" & CountAV & ") " & objAntiVirus.displayName & " v" & objAntiVirus.versionNumber & Enter');
WriteLn(f, 'Next');
// Write to File
WriteLn(f, 'objFile.WriteLine(Info)');
WriteLn(f, 'objFile.Close');
CloseFile(f);
ShellExecute(0, 'open', PChar(VBSFile), nil, nil, SW_HIDE);
// 2 sec warten, is genug
Sleep(2000);
SL.LoadFromFile(InfoFile);
for i := 0 to SL.Count -1 do
begin
if Copy(SL[i], 1, 1) = 'F' then
SLFirewall.Add(Copy(SL[i], 2, Length(SL[i])))
else if Copy(SL[i], 1, 1) = 'A' then
SLAntiVirus.Add(Copy(SL[i], 2, Length(SL[i])))
end;
DeleteFile(VBSFile);
DeleteFile(InfoFile);
end;
// aufrufen
procedure TfrmMain.Button1Click(Sender: TObject);
var
SLAntiVirus, SLFirewall: TStringList;
i: Integer;
begin
lbAntiVirus.Clear; // ListBox
lbFirewall.Clear;
SLAntiVirus := TStringList.Create;
SLFirewall := TStringList.Create;
GetFirewallandAntiVirusSoftware(SLAntiVirus, SLFirewall);
for i := 0 to SLAntiVirus.Count -1 do
lbAntiVirus.Items.Add(SLAntiVirus[i]);
for i := 0 to SLFirewall.Count -1 do
lbFirewall.Items.Add(SLFirewall[i]);
end;
und der VBS script wäre dann
Delphi-Quellcode:
Set objSecurityCenter = GetObject("winmgmts:\\.\root\SecurityCenter")
Set colFirewall = objSecurityCenter.ExecQuery("Select * From FirewallProduct",,48)
Set colAntiVirus = objSecurityCenter.ExecQuery("Select * From AntiVirusProduct",,48)
Set objFileSystem = CreateObject("Scripting.fileSystemObject")
Set objFile = objFileSystem.CreateTextFile("C:\Filename.erz", True)
Enter = Chr(13) + Chr(10)
CountFW = 0
CountAV = 0
For Each objFirewall In colFirewall
CountFW = CountFW + 1
Info = Info & "F" & CountFw & ") " & objFirewall.displayName & " v" & objFirewall.versionNumber & Enter
Next
For Each objAntiVirus In colAntiVirus
CountAV = CountAV + 1
Info = Info & "A" & CountAV & ") " & objAntiVirus.displayName & " v" & objAntiVirus.versionNumber & Enter
Next
objFile.WriteLine(Info)
objFile.Close
|