### 方法
```C#
public static void InitializePort()
{
try
{
Microsoft.Win32.RegistryKey hklm = Microsoft.Win32.Registry.LocalMachine;
Microsoft.Win32.RegistryKey software11 = hklm.OpenSubKey("HARDWARE");
//打开"HARDWARE"子健
Microsoft.Win32.RegistryKey software = software11.OpenSubKey("DEVICEMAP");
Microsoft.Win32.RegistryKey sitekey = software.OpenSubKey("SERIALCOMM");
//获取当前子健
String[] Str2 = sitekey.GetValueNames();
//获得当前子健下面所有健组成的字符串数组
int ValueCount = sitekey.ValueCount;
//获得当前子健存在的健值
int i;
for (i = 0; i < ValueCount; i++)
{
Workstation_Main.PortName.Items.Add((string)sitekey.GetValue(Str2[i]));
}
return;
}
catch (Exception)
{
return;
}
}
//网络素材仅限收藏 方便学习
原文:https://www.cnblogs.com/New-HackerHK/p/14864344.html