Get a List of Installed Drivers

gbertoli3 1 Tallied Votes 3K Views Share

Get the Driver's Name, Path, Description, Status, and Start Mode

private void GetDrivers()
        {
            //ListView
            ListView driversListView = new ListView();
            //Columns
            ColumnHeader nameColumn = new ColumnHeader();
            ColumnHeader pathColumn = new ColumnHeader();
            ColumnHeader descriptionColumn = new ColumnHeader();
            ColumnHeader statusColumn = new ColumnHeader();
            ColumnHeader startModeColumn = new ColumnHeader();
            //Declare, Search, and Get the Properties in Win32_SystemDriver
            System.Management.SelectQuery query = new System.Management.SelectQuery("Win32_SystemDriver");
            System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(query);
            foreach (System.Management.ManagementObject ManageObject in searcher.Get())
            {
                //Declare the Main Item
                ListViewItem item = new ListViewItem(ManageObject["Name"].ToString());
                //Create a Collection to hold all of the SubItems
                ListViewItem.ListViewSubItemCollection collection = new ListViewItem.ListViewSubItemCollection(item);
                //Declare All of the SubItems and Get the Appropriate Values
                ListViewItem.ListViewSubItem item2 = new ListViewItem.ListViewSubItem(item, ManageObject["PathName"].ToString());
                ListViewItem.ListViewSubItem item3 = new ListViewItem.ListViewSubItem(item, ManageObject["Description"].ToString());
                ListViewItem.ListViewSubItem item4 = new ListViewItem.ListViewSubItem(item, ManageObject["State"].ToString());
                ListViewItem.ListViewSubItem item5 = new ListViewItem.ListViewSubItem(item, ManageObject["StartMode"].ToString());
                //Add item2, item3, item4, and item5 to the Collection
                collection.Add(item2);
                collection.Add(item3);
                collection.Add(item4);
                collection.Add(item5);
                //Add item to the ListView
                driversListView.Items.Add(item);
            }
            //Resize some of the Columns
            nameColumn.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
            statusColumn.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize);
            startModeColumn.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize);
        }
habermanm 0 Newbie Poster

Thank you for this!

If you are looking for a particular driver, you can add a condition to the query like so:
query.Condition = "Name = 'DriverName'";

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.