Today I researched how to implement in C# a method that forces a COM port to close when it is open by another process. This was found to be a complex task that involves using undocumented Win32 API functions. I didn’t finish it because I found another way to workaround the problem but the idea
I needed to enumerate all COM ports in C# and get their name (e.g. COM1, COM2, …) and their description shown in the Windows Device Manager (e.g. “Communications Port”, “RT USB MRTD Reader”). You could find lots of unmanaged code for doing this but I think this C# code could be helpful to people who