Note that there are some explanatory texts on larger screens.

plurals
  1. POObtain the list of open ports, windows firewall
    primarykey
    data
    text
    <p>I am trying to develop a code that manages the firewall ports using vb.net. The first part is to list all ports enabled. so I am trying this code:</p> <pre><code>Function portsList() Dim ports As INetFwOpenPorts Dim port As INetFwOpenPort Dim myPorts() As INetFwOpenPorts Dim NetFwMgrType As Type = Type.GetTypeFromProgID("HNetCfg.FwMgr", False) Dim mgr As INetFwMgr = DirectCast(Activator.CreateInstance(NetFwMgrType), INetFwMgr) ports = DirectCast(mgr.LocalPolicy.CurrentProfile.GloballyOpenPorts, INetFwOpenPorts) Dim enumerate As System.Collections.IEnumerator = ports.GetEnumerator() Dim i As Integer While enumerate.MoveNext() port = DirectCast(enumerate.Current, INetFwOpenPort) myPorts(i) = port i += 1 End While Dim portAsString() As String For j As Integer = 0 To i portAsString(j) = myPorts(j).ToString Next Return portAsString End Function Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim ports() As String = portsList() Dim n As String = ports.Length Dim newString As String = "" For h As Integer = 0 To n newString = ports(h) &amp; vbNewLine Next RichTextBox1.Text = newString End Sub </code></pre> <p>What I want to do is list all the ports in <code>Richtextbox1</code> after clicking <code>Button4</code>. The error that I am getting is: </p> <blockquote> <p>NullReferenceException was unHandled. Object reference not set to an instance of an object. </p> </blockquote> <p>I am new to Vb, how can I get over this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload