Link to home
Start Free TrialLog in
Avatar of aromberg
aromberg

asked on

VB6 - Netstat code breaking under Windows Server 2003 SBS

Hello!

Here's my problem.  I'm writing a program in VB6 that does the following:  does a netstat output, ignores all listen sockets, and counts the amount of established sockets on port 27046, and dumps that value in a .csv.  Problem is, none of the code examples I find online work on SBS2003.  They work great on XP, but once I throw them on SBS, I get a vary of error messages.  The one that pertains to this section of code is '6 - Overflow'  The code is taken from http://www.ostrosoft.com/vb/projects/iphlpapi.asp, and modified accordingly.  Even the authors code breaks... which is making me pull hairs!


Thanks for any help!

---snip---
Private Sub DoNetstat()
  Open fileName For Append As #1
  Dim pTcpTable As MIB_TCPTABLE
  Dim pdwSize As Long
  Dim bOrder As Long
  Dim nRet As Long
  Dim i As Integer, s As String
frmdebug.Text1 = frmdebug.Text1 & "DoNetStat called (break here)" & vbCrLf
  license = 0
  nRet = GetTcpTable(pTcpTable, pdwSize, bOrder)
  nRet = GetTcpTable(pTcpTable, pdwSize, bOrder)
  For i = 0 To pTcpTable.dwNumEntries - 1
  frmdebug.Text1 = frmdebug.Text1 & "DoNetStat: in for i=" & i & vbCrLf
    If pTcpTable.table(i).dwState - 1 <> MIB_TCP_STATE_LISTEN Then

    frmdebug.Text1 = frmdebug.Text1 & c_ip(pTcpTable.table(i).dwLocalAddr) & ":" & _
        c_port(pTcpTable.table(i).dwLocalPort) & vbTab & _
        c_ip(pTcpTable.table(i).dwRemoteAddr) & ":" & _
        c_port(pTcpTable.table(i).dwRemotePort) & vbTab & _
        c_state(pTcpTable.table(i).dwState - 1) & vbCrLf & "*************" & vbCrLf

    frmdebug.Text1 = frmdebug.Text1 & "DoNetStat: after if, right before bot=" & vbCrLf
        bot = c_port(pTcpTable.table(i).dwLocalPort)
        frmdebug.Text1 = frmdebug.Text1 & "DoNetStat: bot " & bot & vbCrLf
                If (bot = 27046) Then
                    license = license + 1
                    Else
                End If
    End If
  Next
  frmdebug.Text1 = frmdebug.Text1 & "DoNetStat finished.. writing file" & vbCrLf
  Label5.Caption = license
  Write #1, DateTime.Date$, DateTime.Time$, license
  Close #1
  frmdebug.Text1 = frmdebug.Text1 & "File written and closed\n" & vbCrLf
End Sub
---end snip--
ASKER CERTIFIED SOLUTION
Avatar of inthedark
inthedark
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aromberg
aromberg

ASKER

Thanks!  That's what I needed for the most part... the next problem, which I'll detail here... was that the index array was too small... which caused a "9 - Subscript out of bounds error", so I had to go into my module and change the line that said 'table(100) As MIB_TCPROW   'array of TCP connections' to 'table(250) As MIB_TCPROW   'array of TCP connections'.

Thanks a bunch!