<p>The company I work for makes hardware that communicates to the computer though a serial port. Third party companies write software that communicates with our hardware. </p>

<p>There are times when I need to diagnose our hardware. However, a third party software app connects to the serial port when Windows starts up, blocking any other connection. I don't know the name of this application/service and it's not always the same one.</p>

<p>Is there any way to either:</p>

<ul>
<li>Find the name/pid of the app/service that is currently using a given serial port or</li>
<li>Steal the serial port connection from another app.</li>
</ul>

<p>vb.net preferably, but I'll take a language agnostic answer as well.</p>

[{'answer_id': 42208, 'author': 'Adam Davis', 'author_id': 2915, 'author_profile': 'https://Stackoverflow.com/users/2915', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://technet.microsoft.com/en-us/sysinternals/default.aspx" rel="nofollow noreferrer">Sysinternals</a> has a slew of utilities I find very useful and educational for tracking down what processes are doing to the system.</p>\n\n<p>They have a utility that does exactly what you need called <a href="http://technet.microsoft.com/en-us/sysinternals/bb896644.aspx" rel="nofollow noreferrer">Portmon</a>, and give some information on how it works near the bottom of the page.  That info and a few well-asked questions will probably give you everything you need to implement it yourself if the utility isn\'t enough.</p>\n\n<p>-Adam</p>\n'}, {'answer_id': 42285, 'author': 'Rob Walker', 'author_id': 3631, 'author_profile': 'https://Stackoverflow.com/users/3631', 'pm_score': 6, 'selected': True, 'text': '<p>You can use the <a href="http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx" rel="noreferrer">process explorer</a> tool also from SysInternals to search for open handles.  In this case you would want to search for \'Serial\' since it uses device names that may not map to com port numbers. (e.g. COM1 is \\Device\\Serial0 on my system).</p>\n\n<p>If you want to take control of the serial port from another app I think you would need co-operation of the driver.</p>\n'}, {'answer_id': 12146933, 'author': 'Don Kirkby', 'author_id': 4794, 'author_profile': 'https://Stackoverflow.com/users/4794', 'pm_score': 3, 'selected': False, 'text': '<p>As <a href="https://stackoverflow.com/a/42285/4794">Rob Walker said</a>, you can find who\'s using a serial port using <a href="http://technet.microsoft.com/en-us/sysinternals/bb795533.aspx" rel="nofollow noreferrer">Process Explorer</a>. Most of the time, typing <kbd>Ctrl</kbd>+<kbd>F</kbd> and searching for "serial" will show you who has a serial port open, but I just ran into a situation where my "COM3" serial port\'s handle appeared as "\\Device\\VCP0". It may be strange because it was running under VirtualBox with a USB-to-serial connector.</p>\n\n<p>If searching for "serial" and "device\\vcp" don\'t get you any results, you may be able to figure out how serial port handles are named by opening one with a known program. In Process Explorer, display the lower pane with each process\'s open handles by typing <kbd>Ctrl</kbd>+<kbd>L</kbd>. Click on the process that you used to open the serial port and look through the lower pane to see which handles look like they might be a serial port. You can open and close the port while you\'re looking, and the file handle should appear and disappear, as well as being highlighted in green or red. Of course, this is only possible if you have more than one serial port or the serial port you\'re trying to diagnose isn\'t always locked by some mystery process.</p>\n'}]
['https://Stackoverflow.com/questions/42197', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/30/']