Einzelnen Beitrag anzeigen

Dezipaitor

Registriert seit: 14. Apr 2003
Ort: Stuttgart
1.701 Beiträge
 
Delphi 7 Professional
 
#21

Re: Windows Firewall - Eintrag erstellen / löschen / ändern

  Alt 3. Mär 2009, 19:57
So isses besser, imho.

Delphi-Quellcode:
function IsWindowsFirewallServiceActive: Boolean;
var
  SCM, hService: LongWord;
  sStatus: TServiceStatus;
  dwStat: Cardinal;
begin
  SCM := OpenSCManager(nil, nil, SC_MANAGER_ENUMERATE_SERVICE);
  if SCM <> 0 then
  begin
    hService := OpenService(SCM, PChar('SharedAccess'), SERVICE_QUERY_STATUS);
    if hService = 0 then //Vista,Win7
      hService := OpenService(SCM, PChar('MpsSvc'), SERVICE_QUERY_STATUS);

    try
      if (hService <> 0) then
      begin
        if (QueryServiceStatus(hService, sStatus)) then
        begin
          result := sStatus.dwCurrentState = SERVICE_RUNNING;
          exit;
        end;
      end;
    finally
      CloseServiceHandle(SCM);
      CloseServiceHandle(hService);
    end;
  end;

  raise EAccessViolation.Create('Could not determine Firewall Service status');
end;
Christian
Windows, Tokens, Access Control List, Dateisicherheit, Desktop, Vista Elevation?
Goto: JEDI API LIB & Windows Security Code Library (JWSCL)
  Mit Zitat antworten Zitat