2013-01-24 1 views

답변

0

Windows Vista 및 7은 방화벽에 예외를 추가하는 데 사용할 수있는 오히려 강력한 방화벽 API를 제공합니다. 아래 코드는 코드가 관리자 권한으로 실행되는 경우 지정된 응용 프로그램에 대한 Windows 방화벽에 예외를 추가합니다. 응용 프로그램에 % systemroot % \ system32 \ FirewallAPI.dll에 대한 참조를 추가하십시오.

Imports NetFwTypeLib 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 

    ' Create the Application we want to add to the exception list 
    Dim appType As Type = Type.GetTypeFromProgID("HnetCfg.FwAuthorizedApplication") 
    Dim app As INetFwAuthorizedApplication 
    app = DirectCast(Activator.CreateInstance(appType), INetFwAuthorizedApplication) 

    ' Set the application properties 
    app.Name = "Negative0's Sandbox" 
    app.ProcessImageFileName = "C:\Users\Negative0\vbsandbox2.exe" 
    app.Enabled = True 


    ' Get the firewall manager, so we can get the list of authorized apps 
    Dim fwMgrType As Type = Type.GetTypeFromProgID("HnetCfg.FwMgr") 
    Dim fwMgr As INetFwMgr 
    fwMgr = DirectCast(Activator.CreateInstance(fwMgrType), INetFwMgr) 

    ' Get the list of authorized applications from the Firewall Manager, so we can add our app to that list 
    Dim apps As INetFwAuthorizedApplications 
    apps = fwMgr.LocalPolicy.CurrentProfile.AuthorizedApplications 
    apps.Add(app) 

End Sub 

Source

관련 문제