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