2014年1月12日 星期日

從 PID/VID 換算出 GUID 值

public string GetGUID(string VendorID, string ProductID)
        {
            string m_GUID = "";
            ManagementObjectCollection USBControllerDeviceCollection = new ManagementObjectSearcher("SELECT * FROM Win32_USBControllerDevice").Get();
            if (USBControllerDeviceCollection != null)
            {
                foreach (ManagementObject USBControllerDevice in USBControllerDeviceCollection)
                {
                  String Dependent = (USBControllerDevice["Dependent"] as String).Split(new Char[] { '=' })[1];
                    if (Dependent.IndexOf(VendorID) >= 0 && Dependent.IndexOf(ProductID) >= 0)
                    {
                        ManagementObjectCollection PnPEntityCollection = new ManagementObjectSearcher("SELECT * FROM Win32_PnPEntity WHERE DeviceID=" + Dependent).Get();
                        if (PnPEntityCollection != null)
                        {
                            foreach (ManagementObject Entity in PnPEntityCollection)
                            {
                                Guid theClassGuid = new Guid(Entity["ClassGuid"] as String);    // ????GUID 
                                m_GUID = theClassGuid.ToString();
                                return m_GUID;
                            }
                          }
                    }
                }
            }

            return m_GUID;
}

沒有留言:

[c#] process 使用方法

寫法1. Process proc = new Process(); / /PowerShell.exe path proc.StartInfo.FileName = @"c:\Windows\System32\ WindowsPowerShell\v1.0\ powe...