private DriverData GetFTDIBaseDriverInfo(string device_name, DriverTypeDM type) { try { string ft_select = string.Format("SELECT * FROM Win32_PnPEntity WHERE Manufacturer = 'FTDI' and Name like '{0}%'", device_name); return(GetDriverInfo(ft_select, type)); } catch { return(null); } }
private void WriteRemoveRecordLogFile(DriverTypeDM dt) { using (StreamWriter sw = (File.Exists(log_path)) ? File.AppendText(log_path) : File.CreateText(log_path)) { sw.WriteLine("\r\n=================================================================================================="); sw.WriteLine("=================================================================================================="); sw.WriteLine("\r\nRecord Date: {0}", DateTime.Now.ToString()); sw.WriteLine("Action: Driver was removed!\r\n"); sw.WriteLine("Driver type: {0}", GetUserFriendlyDriverType(dt)); sw.WriteLine("=================================================================================================="); } }
private string GetUserFriendlyDriverType(DriverTypeDM dt) { string type = null; switch (dt) { case DriverTypeDM.DRIVER_TYPE_DA2: type = "DRIVER_TYPE_DA2"; break; case DriverTypeDM.DRIVER_TYPE_ID_READER: type = "DRIVER_TYPE_ID_READER"; break; case DriverTypeDM.DRIVER_TYPE_PRINTER: type = "DRIVER_TYPE_PRINTER"; break; case DriverTypeDM.DRIVER_TYPE_TOUCH_SCREEN: type = "DRIVER_TYPE_TOUCH_SCREEN"; break; } return(type); }
private DriverData GetDriverInfo(string query, DriverTypeDM type) { DriverData data = null; ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", query); ManagementObjectCollection moc = searcher.Get(); foreach (var device in moc) { if (data == null) { data = new DriverData(); } data.type = type; data.device_name = device["Name"].ToString(); string q = string.Format("SELECT * FROM Win32_PnPSignedDriver WHERE DeviceID = '{0}'", device.GetPropertyValue("DeviceID")); ManagementObjectSearcher sr = new ManagementObjectSearcher("root\\CIMV2", q.Replace("\\", "\\\\")); ManagementObjectCollection mc = sr.Get(); foreach (var manObj in mc) { if (manObj == null) { break; } data.driver_inf = manObj["InfName"].ToString(); data.driver_version = manObj["DriverVersion"].ToString(); data.mnf_name = manObj["Manufacturer"].ToString(); string date = manObj.GetPropertyValue("DriverDate").ToString(); if (date != null) { data.date_modified = ManagementDateTimeConverter.ToDateTime(date); } if (data.driver_inf != null) { string system_path = Environment.GetEnvironmentVariable("windir"); data.inf_modified = File.GetLastWriteTime(system_path + "\\inf\\" + data.driver_inf); data.inf_modified = data.inf_modified.AddTicks(-data.inf_modified.Ticks % 10000000); } foreach (var queryObj in CIMcollection) { string key = device["DeviceID"].ToString().Replace("\\", "\\\\"); string param = queryObj["Antecedent"].ToString(); if (param.IndexOf(key) > 0) { int len = queryObj["Dependent"].ToString().Length; if (len > 0) { int pos = queryObj["Dependent"].ToString().IndexOf('"'); if (pos != -1) { if (data.driver_file_version != null) { data.driver_file_version += ", "; } data.driver_file_version += GetFileVersion(queryObj["Dependent"].ToString().Substring(pos + 1, len - pos - 2)); pos = queryObj["Dependent"].ToString().LastIndexOf('\\'); if (pos > 0) { if (data.installed_drivers != null) { data.installed_drivers += ", "; } data.installed_drivers += queryObj["Dependent"].ToString().Substring(pos + 1, len - pos - 2); } } } } } } } return(data); }