List Of COM Ports

  • Thread starter Thread starter Krunoslav Ostrouska
  • Start date Start date
Hi Krunoslav,

Here is the piece of code that list the COM ports .

You will need to add a reference to System.Management.dll

Dim moReturn As Management.ManagementObjectCollection
Dim moSearch As Management.ManagementObjectSearcher
Dim mo As Management.ManagementObject

moSearch = New Management.ManagementObjectSearcher("Select * from
Win32_POTSModem")
moReturn = moSearch.Get

For Each mo In moReturn
Debug.WriteLine(mo("Name") & " is attached to " &
mo("AttachedTo"))
Next

Hope this helps you.

Thanks
Raghavendra
 
Hi Raghavendra.
I have tryed it but my ManagementObjectCollection dosent contain anything
(Count=0) !
My C# code:

ManagementObjectCollection managementCol;
ManagementObjectSearcher searcher;
searcher=new ManagementObjectSearcher("Select * from Win32_POTSModem");
managementCol=searcher.Get();
int i=managementCol.Count; // =0 ?!!
foreach (ManagementObject mob in managementCol)
Debug.WriteLine(mob.GetPropertyValue("Name") + "is attached to"
+mob.GetPropertyValue("AttachedTo"));

WinXPProf, VS2003
Do you have any ideas?
Thanks
Kruno
 
Back
Top