how do I find out which program is using the port and how do I disconnect it?
I don't know but I just found something that might help using WMIC.
portconnector
Data presented corresponds to this
https://msdn.microsoft.com/en-us/library/aa394358%28v=vs.85%29.aspx
Unfortunately it appears that the Status field is not being used correctly. Also, I don't know how accurate this will be because it is showing me I have a PS2Mouse on my Surface! ; }
Hmm... more usefully I think in the sidebar I noticed Win32_SerialPort which led me to
Path CIM_SerialController
(e.g. in WMIC) which is showing me more believable information about some COM ports that are being implemented using Bluetooth.
Thanks for making me find this! ; )
So, for example, presumably you may be able to get some information about your COM2 by entering
wmic.exe Path CIM_SerialController where (DeviceID="COM2") Get /Format:list
Here's one where I don't even need a where clause. (I did a Get-WMIObject -List *serial* to find this.)
wmic.exe Path Win32_POTSModemToSerialPort Get /format:list
As for getting a Reset done it appears that this may not be implemented by WMI.
FYI