Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load End Sub Private Sub btnBrowse_Click(sender As Object, e As EventArgs) Handles btnBrowse.Click Dim newFile As New OpenFileDialog If newFile.ShowDialog = Windows.Forms.DialogResult.OK Then If My.Computer.FileSystem.FileExists(newFile.FileName) Then txtAppPath.Text = newFile.FileName txtRuleName.Text = IO.Path.GetFileNameWithoutExtension(newFile.FileName) End If End If End Sub Private Sub btnCommand_Click(sender As Object, e As EventArgs) Handles btnCommand.Click MsgBox(WriteRule(txtAppPath.Text, txtRuleName.Text)) End Sub Public Function WriteRule(ByVal xAppPath As String, ByVal xRuleName As String) As Boolean Try Const NET_FW_SCOPE_ALL = 0 Const NET_FW_IP_VERSION_ANY = 2 Dim fwMgr = CreateObject("HNetCfg.FwMgr") Dim profile = fwMgr.LocalPolicy.CurrentProfile Dim app = CreateObject("HNetCfg.FwAuthorizedApplication") app.ProcessImageFileName = xAppPath app.Name = xRuleName app.Scope = NET_FW_SCOPE_ALL app.IpVersion = NET_FW_IP_VERSION_ANY app.Enabled = True profile.AuthorizedApplications.Add(app) Return True Catch ex As Exception Return False End Try End Function End Class