我有一个可以添加防火墙异常的 VB.NET 例程,问题是我必须在所有类型的网络下添加一个异常,无论是私有的还是公共的。但是这个例程在 Windows 防火墙的私有类别下添加了一个例外。
我的代码:
Private Sub AddApp()
Dim appType As Type = Type.GetTypeFromProgID("HnetCfg.FwAuthorizedApplication")
Dim app As INetFwAuthorizedApplication
app = DirectCast(Activator.CreateInstance(appType), INetFwAuthorizedApplication)
' Set the application properties
app.Name = "My App"
app.ProcessImageFileName = "C:\Users\klein\AppData\Roaming\Microsoft\Windows\MyApp.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