File Exchange

image thumbnail

Identify Serial COM devices by friendly name in Windows

version (1.94 KB) by Benjamin Avants
Uses Windows registry information to ID Serial COM devices


Updated 08 Apr 2014

View Version History

View License

This function scans the Windows registry in two places and associates active COM ports with their registered "Friendly Name". The function returns an N x 2 cell array where N is the number of active COM ports. The first column contains the friendly names of the devices where they exist and the second contains their COM number. If no devices with friendly names are found, devices is empty.
This function is not necessarily optimized but it is my solution to identifying serial devices connected by virtual COM port in Windows without having to query every device. If multiple devices with the same friendly name are connected to the computer, the output will contain both devices with their COM ports but they will be otherwise indistinguishable by this function.

Cite As

Benjamin Avants (2021). Identify Serial COM devices by friendly name in Windows (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (10)

Imran Khan

Didn't try this submission out, but Serge's function in the comments worked well for me (huge thanks!). I would recommend modifying this line in it though:

names = regexp(str,'FriendlyName *REG_SZ *(?<name>.*?) \((?<port>COM.*?)\)','names', 'dotexceptnewline');

The .* was matching all the initial non-COM port objects on my PC and reporting them as the first COM port friendly name because .* matches newline by default on MATLAB regex's


I prefer this simpler and more complete version:

function ports = comports
%List serial COM ports as a struct with names (Windows only).
% ports = comports -struct with fields: type, port, name
%To improve speed (x10) add jsystem to the path from here:

if err
ports = [];
ports = regexp(str,'\\Device\\(?<type>[^ ]*) *REG_SZ *(?<port>COM.*?)\n','names');
cmd = 'REG QUERY HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\ /s /f "FriendlyName" /t "REG_SZ"';
if exist('jsystem','file')==2 %~10x faster then 'system'
[~,str] = jsystem(cmd,'noshell');
[~,str] = system(cmd);
names = regexp(str,'FriendlyName *REG_SZ *(?<name>.*?) \((?<port>COM.*?)\)','names');
[i,j] = ismember({ports.port},{names.port});
[ports(i).name] = names(j(i)).name;

Nicholas Guglielmin

Lorgio Teodovich

Does not report the active devices correctly. Missing the Enum services. I have made modifications to the code in

Lars Risbo

It seems that DOS is not recognising the REG command? Running Win7/64 and Matlab 2017a

>> [~, list] = dos(['REG QUERY ' Skey]);
>> list

list =

''REG' is not recognized as an internal or external command,
operable program or batch file.

Jim Hokanson

Hi Benjamin,

As Matthias points out your current code implementation assumes USB implementations of a serial port. You can point to \ENUM\ instead and get everything. Also, for what it is worth, I would prefer to see the use of structures instead of cell arrays. Overall though this was helpful in getting me started.


bien le

great work Benjamin!


Hi Benjamin,

was not working for me until I changed the \ENUM\USB\ to \ENUM\FTDIBUS for a list of Serial Ports.

Now it works for me, thanks a lot!


To my knowledge, this is the first function that does this. Its faster than similar functions that start by trying to open a COM ports or using the system('mode') command, and it's better because it helps find the particular device you're looking for.


MATLAB Release Compatibility
Created with R2012b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!