private static int testNewCheckDevice() { string deviceManagerID = @"USB\VID_072F&PID_2223\7"; if (!string.IsNullOrEmpty(deviceManagerID)) { List <string> miList = new List <string>(); miList.Add("&MI_00"); miList.Add("&MI_01"); miList.Add("&MI_02"); miList.Add("&MI_03"); bool hasMI = false; string oriMI = ""; if (deviceManagerID.ToUpper().IndexOf("&MI_0") > -1) { oriMI = deviceManagerID.Substring(deviceManagerID.ToUpper().IndexOf("&MI_0"), 6); hasMI = true; } foreach (var mi in miList) { string tmpDeviceManagerID = deviceManagerID; if (hasMI) { tmpDeviceManagerID = tmpDeviceManagerID.Replace(oriMI, mi); } ManagementObject device = DeviceManagerService.GetPnPDeviceByID(tmpDeviceManagerID); if (device != null) { foreach (PropertyData propertyData in device.Properties) { if (propertyData.Name != "ConfigManagerErrorCode") { continue; } return(Convert.ToInt32(propertyData.Value)); } } if (!hasMI) { break; } } return(0); } return(-1); }
public virtual int CheckDeviceManager() { try { if (string.IsNullOrEmpty(deviceManagerName) && string.IsNullOrEmpty(deviceManagerID)) { return(-1); } if (!string.IsNullOrEmpty(deviceManagerID)) { ManagementObject device = DeviceManagerService.GetPnPDeviceByID(deviceManagerID); if (device != null) { foreach (PropertyData propertyData in device.Properties) { if (propertyData.Name != "ConfigManagerErrorCode") { continue; } return(Convert.ToInt32(propertyData.Value)); } } else { return(-1); } } if (!string.IsNullOrEmpty(deviceManagerName)) { ManagementObject device = DeviceManagerService.GetPnPDeviceByName(deviceManagerName); if (device != null) { foreach (PropertyData propertyData in device.Properties) { if (propertyData.Name != "ConfigManagerErrorCode") { continue; } return(Convert.ToInt32(propertyData.Value)); } } else { if (string.IsNullOrEmpty(deviceManagerID)) { return(-1); } } } return(-1); } catch (Exception ex) { throw new RMSAppException(this, "0500", "CheckDeviceManager failed. " + ex.Message, ex, true); } }