Enumerate open ports in same process - windows

Is there any way in Windows for a process to enumerate all the open ports/sockets it is using? I'm trying to track down some high port usage in my app, but my app uses very few, so it must be some other DLL getting loaded into the process.

Windows' own command-line netstat utility, as well as the SysInternals' TCPView app, can display the name of the process that owns each open port.
If you want to enumerate this information programmably, you will have to enumerate Windows' port routing tables manually and map them to your process. On XP, you can use AllocateAndGetTcpExTableFromStack() and AllocateAndGetUdpExTableFromStack(). On Vista and later, you can use GetExtendedTcpTable() and GetExtendedUdpTable() instead. Both sets of functions can return the Process ID of each open IP/Port, which you can then compare to the result of GetCurrentProcessId().

Related

Create two independent desktops?

I'm running some kind of POS application which makes exclusive use of the whole desktop to not to let the user access any of the Windows system functions. To do this, I use the WinAPI functions
CreateDesktop()
OpenDesktop()
to open an own desktop and to start this application there. This works fine for one desktop.
Now there is the possibility to connect a second monitor to this PC. Windows by default extends its desktop over the full area of both monitors. But this is not a solution for my application, here I want to start two GUIs in the same manner as described above but on every monitor exclusively.
But: I do not see any possibility to hand over a monitor identifier to the functions CreateDesktop()/OpenDesktop(). So any idea how this can be done?
Thanks!

Win32API: Identify which program is using a serial COM port

Win32API environment.
I need to identify which program is using a particular serial COM port. For example, if putty has opened COM4 and I later try to start another program that also wants to open COM4, how can I discover that putty is the program preventing this?
In other words, assuming I already have a list of all ports installed on the system, how do I work backwards to discover which programs have opened which ports?

How find a process which removed/moved a given file in Windows

Suppose I have some files removed (or probably moved or renamed) in a Windows machine. Now I would like to find out what process removes/moves them. How can I do it?
Assuming that you need this in code, the only option is to have a filesystem filter driver intercept the requests and capture the information you need. Our CallbackFilter product lets one do this in user-mode (the driver is included).
Other options (not in code) are enable audit on the files in question and use ProcMon tool (Process Monitor by Sysinternals) to monitor the files.

Use of parallel / serial port redirection to transfer data from Terminal desktop to local computer

Amongst features of terminal desktop services running RDP port, there is port redirection of parallel/serial from remote to local PC.
Can this redirection be somehow used to transfer large data to avoid using Clipboard (due to the known stack bug which may force user to close terminal desktop and re-logon)?
To transmit and receive data I'd use VBA for Excel on both terminal desktop as well as in local PC. Both would be running infinetely or at the same time.
Please advise if it's possible.
At least one company makes a library for doing Kermit (i.e. serial file transfer), which includes VBA support and samples for Access, Excel and Word.
It's not cheap though, and there are a lot of better ways of sending data around than serial file transfer protocols over virtual serial ports so I'd strongly consider better alternatives (file sharing, TCP sockets etc.).

listing processes and their connections

I would like to make a small program listing running programs on my
computer - this seems simple. But I would also like to detect their
connections, ex.: I detect a running Internet Explorer (or other
browser), but I would like to know which websites it is visiting.
Another example; I detect Word is running, and would like to know what
document(s) it is working with. Is it possible to query the http-
protocol to discover online connections? And how about programs that
open local resources? So, listing running programs and their
connections is what I want to do - and do I have to poll for it every minute or is
there better ways of watching these processes?
It must be able to run on MS Windows, but the programminglanguage is not important
Thanx
Ask
You might want to consider some of the pre-existing tools capable of doing this. Both Windows NT and most Unixes come with the "netstat" command.
Windows NT: netstat -b
Unix: netstat -p
I like using Process Monitor. Find it here: http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx

Resources