Link to home
Start Free TrialLog in
Avatar of ippopotimus
ippopotimus

asked on

Get the name of a window related to a network connection

In delphi, is there any way to enumerate all network connections currently active and find out what window/process they were created from. Thanks in advance.
Avatar of steve_hsk
steve_hsk

Hi ippopotimus ...

The short answer is of course YES (but I only know for XP) :-O ...

Stage One : Retreiving the list of Active Connections (NetStat through code) :
I'm not being lazy here, but I've just answered another question that asked how to do this ...
https://www.experts-exchange.com/questions/20552007/Discount-connection.html

Stage Two : Associating this data with the process using it :
If you are doing this for XP, this is relatively easy, using the undocumented IPHlpAPI function - AllocateAndGettcpExTableFromStack

The following site provides a simple example in C (sorry - haven't had the time to convert this to Delphi yet) that demonstrates listing the active connections and associating their Process IDs (PID)s
http://www.vbcity.com/forums/topic.asp?tid=8785

A tutorial explaining this method :
http://www.pcquest.com/content/coding/102082103.asp

A genral IPHlpAPI delphi site (in french) ... but good code example ...
http://iglooduhack.free.fr/delphi_ip_helper.php

For NT4 and 2000, I'm convinced that this is available in the MIB, but I can't find it at all !!!

The only other idea was to interface with the NDIS drivers and retrieve the PID vs Socket bindings.

I'll keep looking however ... This is actually an old project of mine that I never completed for NT4/2000 !!!

Hope this gets you started,
STeve

As an extra, I know this is possible on the 2000, NT4 platforms ... so dont give up ...

An excellant website (!) in general, but it has 2 utilities that list port Vs PID : TCPView.EXE and TDIMon.EXE :

http://www.sysinternals.com/ntw2k/utilities.shtml

STeve
Avatar of ippopotimus

ASKER

i really need this for windows 2000
HI,
Try WNetOpenEnum, WNetCloseEnum, WNetEnumResource functions.
Sincerely,
Nestorua.
Ipp ... I'm still trying ... your question has renewed my interest ... if you make any progress, let me know :-)

Nestorua ...

"The WNetCloseEnum function ends a network resource enumeration started by a call to the WNetOpenEnum function."

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wnet/wnet/wnetcloseenum.asp

From my understanding, this API set controls the actual network connection (RAS/LAN/WAN). I think (?) that Ipp wants to be able to list sockets that have active connections (IP/Port), owned by processes or apps.

I'm convinced that you can do this via the TDI Layer, using TDI_CONNECTION_INFO or TDI_CONNECTION_INFORMATION. Will keep working on it !

STeve
ippopotimus:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

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