07-06-2012, 01:11 PM
I hope someone is still monitoring this thread. I'm trying to get a process name if a port is found to be in use. I'm hoping someone can help me leverage the information here to get the job done.
My current code (installer custom action) works to detect if the port is in use, but I want to take it a step further and get the process name of the port user. If is a certain value I will allow the use of that port in the install dialog. If not, I will notify that port is in use.
Anyway, here's my code...
Like I said, this code works pretty well or so it seems. I just want to add a layer to it to check the process by PID I guess, grab the name and if = to or contains "MyValue" then allow the in use port to be selected or used during the install.
I hope someone can help.
My current code (installer custom action) works to detect if the port is in use, but I want to take it a step further and get the process name of the port user. If is a certain value I will allow the use of that port in the install dialog. If not, I will notify that port is in use.
Anyway, here's my code...
Code:
Dim hostname As String = "127.0.0.1"
Dim port As Integer
Dim ipa As IPAddress = DirectCase(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)
sock.Connect(ipa, port)
If sock.Connected = True Then
session.item("PORT_VALID") = "" 'Property value returned to installer.
End If
sock.Close
Like I said, this code works pretty well or so it seems. I just want to add a layer to it to check the process by PID I guess, grab the name and if = to or contains "MyValue" then allow the in use port to be selected or used during the install.
I hope someone can help.