Vb.net 添加防火墙例外
我正在处理服务器/客户端TCP通信,它工作正常,尽管我无法制作应用程序将软件添加到Windows防火墙例外。我确实找到了一个样本,但它不起作用 我的代码:Vb.net 添加防火墙例外,vb.net,firewall,tcplistener,windows-firewall,Vb.net,Firewall,Tcplistener,Windows Firewall,我正在处理服务器/客户端TCP通信,它工作正常,尽管我无法制作应用程序将软件添加到Windows防火墙例外。我确实找到了一个样本,但它不起作用 我的代码: Imports NetFwTypeLib Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load Dim appType As Type = Type.GetTypeFromProgID("
Imports NetFwTypeLib
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
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\documents\visual studio 2012\projects\tcp_server\tcp_server\bin\debug\tcp_server.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
End Class
代码运行正常,未检测到异常。但是,在加载表单后,程序不会列出
谢谢。看看这个:
说明是针对
SQLServer
,如果您能提供代码,说明它如何在服务器/客户端TCP上工作,那就更好了。谢谢,但我成功地使它工作了,问题是程序必须以管理员身份运行。