You definitely don't want to do it this way. This is fragile, and not even guaranteed to find all serial ports.
Use the documented PNP APIs to discover and enumerate devices of specific device classes. For starters, look at SetupDiEnumDeviceInterfaces in Win32 SDK. There may be easier ways to do this under managed code, such as MC++ or WMI. Still, it's far, far superior to groveling through the registry. -- arlie -----Original Message----- From: Unmoderated discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED] On Behalf Of Vipul Patel Sent: Thursday, April 29, 2004 5:40 AM To: [EMAIL PROTECTED] Subject: [ADVANCED-DOTNET] .NET function for finding out COM ports on a PC Hi all, I need to find out COM ports available on the PC on which my application will be deployed. I am using the following code ===START OF CODE=== RegistryKey myKey = Registry.LocalMachine.OpenSubKey(@"HARDWARE\DEVICEMAP\SERIALCOMM"); if (myKey != null) { string[] str = myKey.GetValueNames(); for(int i = 0 ; i < str.Length; i++) { if(myKey.GetValue(str[i]).ToString().StartsWith("COM")) { // My logic here } } } ===END OF CODE=== But I feel that not all application users will have rights to read the registry. Is there any other mechanism to determine the number of COM ports available on a PC? Regards, Vipul Patel =================================== This list is hosted by DevelopMentorR http://www.develop.com Some .NET courses you may be interested in: NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles http://www.develop.com/courses/gaspdotnetls View archives and manage your subscription(s) at http://discuss.develop.com =================================== This list is hosted by DevelopMentor� http://www.develop.com Some .NET courses you may be interested in: NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles http://www.develop.com/courses/gaspdotnetls View archives and manage your subscription(s) at http://discuss.develop.com
