Beispiel #1
0
        private List <DriverData> GetVideoControllertDriverInfo()
        {
            List <DriverData> VideoDriver = new List <DriverData>(3);
            DriverData        data        = null;
            string            query       = "SELECT * FROM Win32_VideoController";

            ManagementObjectSearcher   ms  = new ManagementObjectSearcher("root\\CIMV2", query);
            ManagementObjectCollection moc = ms.Get();

            foreach (ManagementObject obj in moc)
            {
                if (data == null)
                {
                    data = new DriverData();
                }
                data.type              = DriverTypeDM.DRIVER_TYPE_VIDEO;
                data.device_name       = obj["Name"].ToString();
                data.driver_version    = obj["DriverVersion"].ToString();
                data.driver_inf        = obj["InfFilename"].ToString();
                data.installed_drivers = obj["InstalledDisplayDrivers"].ToString();
                VideoDriver.Add(data);
            }

            return(VideoDriver);
        }
Beispiel #2
0
 private void AddToDriverDB(DriverData item)
 {
     if (item != null)
     {
         DriverDB.Add(item);
     }
 }
Beispiel #3
0
 private void WriteLogFile(DriverData dd, string action)
 {
     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: {0}!\r\n", action);
         sw.WriteLine("Driver type: {0}", GetUserFriendlyDriverType(dd.type));
         sw.WriteLine("Driver name: {0}", dd.device_name);
         sw.WriteLine("Manufacturer name: {0}", dd.mnf_name);
         if (dd.type != DriverTypeDM.DRIVER_TYPE_PRINTER)
         {
             sw.WriteLine("Driver version: {0}", dd.driver_version);
         }
         else
         {
             sw.WriteLine("Driver version: {0}", dd.driver_file_version);
         }
         sw.WriteLine("Installed drivers: {0}", dd.installed_drivers);
         sw.WriteLine("Inf File: {0}", dd.driver_inf);
         sw.WriteLine("Modified: {0}", dd.inf_modified.ToLongDateString());
         sw.WriteLine("==================================================================================================");
     }
 }
Beispiel #4
0
        private void SaveDriver(DriverData dd)
        {
            switch (dd.type)
            {
            case DriverTypeDM.DRIVER_TYPE_DA2:
                Properties.Settings.Default.DA2_DRIVER_INF_MODIFIED  = dd.inf_modified;
                Properties.Settings.Default.DA2_DRIVER_VERSION       = dd.driver_version;
                Properties.Settings.Default.DA2_DRIVER_DATE_MODIFIED = dd.date_modified;
                Properties.Settings.Default.Save();
                break;

            case DriverTypeDM.DRIVER_TYPE_ID_READER:
                Properties.Settings.Default.ID_READER_DRIVER_INF_MODIFIED  = dd.inf_modified;
                Properties.Settings.Default.ID_READER_DRIVER_VERSION       = dd.driver_version;
                Properties.Settings.Default.ID_READER_DRIVER_DATE_MODIFIED = dd.date_modified;
                Properties.Settings.Default.Save();
                break;

            case DriverTypeDM.DRIVER_TYPE_PRINTER:
                Properties.Settings.Default.PRINTER_DRIVER_INF_MODIFIED  = dd.inf_modified;
                Properties.Settings.Default.PRINTER_DRIVER_VERSION       = dd.driver_version;
                Properties.Settings.Default.PRINTER_DRIVER_DATE_MODIFIED = dd.date_modified;
                Properties.Settings.Default.Save();
                break;

            case DriverTypeDM.DRIVER_TYPE_TOUCH_SCREEN:
                Properties.Settings.Default.TOUCH_SCREEN_DRIVER_INF_MODIFIED  = dd.inf_modified;
                Properties.Settings.Default.TOUCH_SCREEN_DRIVER_VERSION       = dd.driver_version;
                Properties.Settings.Default.TOUCH_SCREEN_DRIVER_DATE_MODIFIED = dd.date_modified;
                Properties.Settings.Default.Save();
                break;
            }
        }
Beispiel #5
0
        private DriverData GetPrinterDriverInfo()
        {
            string     key  = null;
            DriverData data = null;
            ManagementObjectSearcher   ms  = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Printer WHERE default = 'true'");
            ManagementObjectCollection moc = ms.Get();

            foreach (var manObj in moc)
            {
                if (manObj == null)
                {
                    break;
                }
                if (data == null)
                {
                    data = new DriverData();
                }
                // data.driver_inf = manObj["InfName"].ToString();
                data.type           = DriverTypeDM.DRIVER_TYPE_PRINTER;
                data.driver_version = manObj["DriverName"].ToString();
                key = manObj.GetPropertyValue("DeviceID").ToString().Replace("\\", "\\\\");

                foreach (var queryObj in CIMcollection)
                {
                    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('"');
                            int 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);
        }
Beispiel #6
0
        public DriverData GetPrinterDriverInfoA()
        {
            DriverData      data     = null;
            PrinterSettings settings = new PrinterSettings();

            WinSpoolPrinterInfo wpi = new WinSpoolPrinterInfo();

            WinSpoolPrinterInfo.DRIVER_INFO_8?Info8 = wpi.GetPrinterInfo(settings.PrinterName);

            if (Info8.HasValue)
            {
                data                   = new DriverData();
                data.type              = DriverTypeDM.DRIVER_TYPE_PRINTER;
                data.device_name       = Info8.Value.pName;
                data.driver_inf        = GetShortPath(Info8.Value.pszInfPath);
                data.installed_drivers = GetShortPath(Info8.Value.pDriverPath);
                if (Info8.Value.pDriverPath != null)
                {
                    data.driver_file_version = GetFileVersion(Info8.Value.pDriverPath);
                }
                if (Info8.Value.pszInfPath != null)
                {
                    data.inf_modified = File.GetLastWriteTime(Info8.Value.pszInfPath);
                }
                else if (Info8.Value.pDriverPath != null)
                {
                    data.inf_modified = File.GetLastWriteTime(Info8.Value.pDriverPath);
                }
                data.inf_modified = data.inf_modified.AddTicks(-data.inf_modified.Ticks % 10000000);
                data.mnf_name     = Info8.Value.pszMfgName;
                long ft = (((long)Info8.Value.ftDriverDate.dwHighDateTime) << 32) + Info8.Value.ftDriverDate.dwLowDateTime;
                data.date_modified = DateTime.FromFileTime(ft);


                if (Info8.Value.dwlDriverVersion != null)
                {
                    data.driver_version = Info8.Value.dwlDriverVersion.ToString();
                }
            }

            return(data);
        }
Beispiel #7
0
        private void TrackDriversChange()
        {
            string action = null;

            foreach (OldDriversData odd in OldDriverDB)
            {
                var item = DriverDB.Find(x => x.type == odd.type);
                if (item == null)
                {
                    // removed or has never been installed
                    if (odd.inf_modified.Year > 1900)
                    {
                        // removed
                        WriteRemoveRecordLogFile(odd.type);
                        DriverData d = new DriverData();
                        d.inf_modified = new DateTime(1900, 1, 1);
                        d.type         = odd.type;
                        SaveDriver(d);
                    }
                }
                else
                {
                    if (String.Compare(odd.driver_version, item.driver_version) != 0 ||
                        DateTime.Compare(odd.inf_modified, item.inf_modified) != 0)
                    {
                        // has been modified
                        SaveDriver(item);
                        if (odd.inf_modified.Year > 1900)
                        {
                            action = "Driver replaced the old one";
                        }
                        else
                        {
                            action = "Driver was first time detected";
                        }

                        WriteLogFile(item, action);
                    }
                }
            }
        }
Beispiel #8
0
        private DriverData GetTouchScreenDriverInfo()
        {
            DriverData dm = null;

            try
            {
                string elo_select = "SELECT * FROM Win32_PnPEntity WHERE Manufacturer = 'Elo Touch Solutions'";
                dm = GetDriverInfo(elo_select, DriverTypeDM.DRIVER_TYPE_TOUCH_SCREEN);

                if (dm == null)
                {
                    string _3m_select = "SELECT * FROM Win32_PnPEntity WHERE Manufacturer = '(3M devices)'and Name like '%Sensor%'";
                    dm = GetDriverInfo(_3m_select, DriverTypeDM.DRIVER_TYPE_TOUCH_SCREEN);
                }
            }
            catch
            {
                dm = null;
            }

            return(dm);
        }
Beispiel #9
0
        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);
        }