Home General VB/VBA Check if port is in Use
20 | 05 | 2012
This site has been updated and renewed. You have followed an old link.

Click here to go to the new site

http://www.visiblevisual.com/jupgrade

Check if port is in Use PDF Print E-mail
User Rating: / 0
PoorBest 
Tutorials
Written by Administrator   

Use to function below to check if a port is in use. For instance to test port 80 IsPortinUse(80) will return a true/false status.

[code]

Private Function IsPortinUse(ByVal PortNumber As IntegerAs Boolean
'*************************************
'**** Code from VisibleVisual.co' ****
'*************************************
Dim oSocket As Object
Dim bAns As Boolean
 
On Error Resume Next
Set oSocket = CreateObject("MSWinsock.Winsock.1")
 
    If Err.Number > 0 Then
        Err.Raise 30000, , "Could not create winsock object"
        Exit Function
    End If
 
Err.Clear
 
oSocket.LocalPort = PortNumber
oSocket.Listen
 
bAns = Err.Number = 10048 'port is busy
oSocket.Close
Set oSocket = Nothing
IsPortinUse = bAns
 
End Function
 
 [/code]

 

 

Add comment


Security code
Refresh

This site has been updated and renewed. You have followed an old link.

Click here to go to the new site

http://www.visiblevisual.com/jupgrade