Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Delphi: Общие вопросы > Определение работы брандмауэра Windows


Автор: vanexe1 23.3.2009, 09:37
Здравствуйте 
У меня возникла необходимость в программном определении состояния брандмауэра Windows XP, работает не работает. 
Например я нажимаю на кнопку и выскакивает сообщение следующего содержания, Брандмауэр Windows работает или не работает.
На http://msdn.microsoft.com/ нашёл  тему по сути как я понял скрип но не разобрался.
Verifying Windows Firewall is Enabled
********************************************************************
The following example shows a verification of the status of the Windows Firewall.
Copy Code
Option Explicit
'Create Shell object
Dim objShell
set objShell = CreateObject("Shell.Application")
'Declare Firewall variables
Dim fwMgr
Dim profile
'Verify that the SharedAccess service is running. If it isn't, then start it.
If objShell.IsServiceRunning("SharedAccess") = FALSE Then
    objShell.ServiceStart "SharedAccess", TRUE
    'Sleep 1 second to make sure the service is started
    ' before trying to create the objects below. If there
    ' is no sleep, then the script is too fast and the
    ' firewall objects can't be created.
    WScript.Sleep 1000
End If
WScript.Echo("SharedAccess is running: " & objShell.IsServiceRunning("SharedAccess"))
' Firewall objects have to be created after making sure
' the service is running. If the service isn't running,
' the script will fail.
' Create the firewall manager object.
Set fwMgr = CreateObject("HNetCfg.FwMgr")
' Get the current profile for the local firewall policy.
Set profile = fwMgr.LocalPolicy.CurrentProfile
'Verify that the Firewall is enabled. If it isn't, then enable it.
If profile.FirewallEnabled = FALSE Then
    profile.FirewallEnabled = TRUE
End If
WScript.Echo("Firewall Enabled: " & profile.FirewallEnabled)
WScript.Echo("Firewall Exceptions Not Allowed: " & profile.ExceptionsNotAllowed)
***********************************************************************
Есть еще параметры реестра, используя которые в рег файле можно отрубить брандмауэр. Можно ли проверять их судить о том что брандмауэр включен или отключен. Я включал отключал его так и не понял по этим параметрам.
*************************************************************************
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Security Center]      
"FirewallOverride"=dword:00000001        
 
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced]  
"DisableThumbnailCache"=dword:00000001  
;Disable Firewall Notifications  
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Security Center]  
"FirewallDisableNotify"=dword:00000001  
;Disable Automatic Updates Notifications  
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Security Center]  
"UpdatesDisableNotify"=dword:00000001  
;Disable Anti-virus Notifications  
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Security Center]  
"AntiVirusDisableNotify"=dword:00000001
**********************************************************************
   

Автор: Quartz 23.3.2009, 15:49
Минимальный пример, переделанный на Delphi (требуется как минимум WinXP SP2):
Код

//...
uses
  ComObj, NetFwTypeLib_TLB;

procedure TForm1.FormCreate(Sender: TObject);
var
  fwMgr   : INetFwMgr;
  profile : INetFwProfile;
begin
  fwMgr := CreateOleObject('HNetCfg.FwMgr') as INetFwMgr;
  profile := fwMgr.LocalPolicy.CurrentProfile;
  if profile.FirewallEnabled = false then
    ShowMessage( 'Firewall disabled!' );
end;

Модуль NetFwTypeLib_TLB получаем так: Component \ Import Component \ Import a Type Library \ NetFwTypeLib (hnetcfg.dll\3).
На всякий случай прикрепляю и его...

Автор: vanexe1 23.3.2009, 19:54
Огромное спасибо! все работает. класс

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)