July 5th, 2012, 04:11 PM
Get a Process Name Using a Port...
I'm wondering how I can get the name of a process on a port. During our install I am calling the following code to see if a user entered port is open. If not, I want to get information on the process tied to the port because if let's say the name is a certain value, I'll allow the entry...
As is, the code runs OK for me in that if the port is in use, there is notification. I would like to do a second check to see what process is running on the selected port. If is is the process that is intended for this port, I want to allow the entry even though it is in use.
Dim hostname As String = "127.0.0.1"
Dim port As Integer
Dim ipa As IPAddress = DirectCast(Dns.GetHostAddresses(hostname)(0), IPAddress)
Dim sock As New System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp)
'Port will have a value grabbed from the running installer (Session.Item)...
If sock.Connected = True Then
'Connection in use...port not available
session.Item("PORT_VALID") = ""
Any help is Greatly appreciated!!
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.