2009-08-31 115 views

回答

0

我剛剛發現下面的C#WMI代碼似乎做了這項工作。但這是可靠的嗎?

 string deviceid = string.Empty; 
     ManagementObjectSearcher searcher = new ManagementObjectSearcher ("Select * from WIN32_SerialPort"); 
     foreach (ManagementObject port in searcher.Get()) 
     { 
      string name = port.GetPropertyValue ("Name") as string; 
      string provider = port.GetPropertyValue ("ProviderType") as string; 
      if (provider == null) 
      { 
       deviceid = port.GetPropertyValue ("DeviceId") as string; 
      } 
     }