0
我正在进行服务器/客户端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("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',它会更好,如果你能提供代码,显示OP它是如何工作的服务器/客户端TCP。 –
谢谢,但我设法使它工作,问题是该程序必须以管理员身份运行。 – blacblu