public MainForm() { InitializeComponent(); ManagementObjectSearcher objSearcher = new ManagementObjectSearcher("Select * from Win32_PnPSignedDriver"); ManagementObjectCollection objCollection = objSearcher.Get(); foreach (ManagementObject obj in objCollection) { var FriendlyName = (string)obj["FriendlyName"] ?? (string)obj["DeviceName"] ?? "Unknown"; var DeviceName = (string)obj["DeviceName"] ?? "Unknown"; var Manufacturer = (string)obj["Manufacturer"] ?? "Unknown"; var ClassGuid = (string)obj["ClassGuid"] ?? "Unknown"; var DeviceClass = (string)obj["DeviceClass"] ?? "Unknown"; if (!treeView1.Nodes.ContainsKey(DeviceClass)) { TreeNode classNode = new TreeNode(DeviceClass); classNode.Name = DeviceClass; treeView1.Nodes.Add(classNode); } var deviceNode = new DeviceNode(); deviceNode.Text = FriendlyName; deviceNode.Name = ClassGuid; deviceNode.FriendlyName = FriendlyName; deviceNode.Manufacturer = Manufacturer; treeView1.Nodes[DeviceClass].Nodes.Add(deviceNode); } }
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { if (e.Node.Level == 0) { return; } DeviceNode node = (DeviceNode)e.Node; textBox1.Text = node.FriendlyName; textBox2.Text = node.Name; textBox3.Text = node.Manufacturer; }