I am trying to find PCI devices' HW IDs and Descriptions. I have used Win32_PnPEntity class as a beginning and wrote a code like below,that code is working on Win7 perfectly but is not working on Win10. I get error like below image.
I have tried WMI settings in services, I have checked root and CIMv2 security options but all options are like need to be. Could you please help me? If it is impossible to do on Win10 please tell me.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Management;
using Microsoft.Win32;
using System.Text.RegularExpressions;
namespace HWINFO
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string HWID = "";
public (List<string>, List<string>) PnpDeviceCheck()
{
List<string> PnPDeviceDescriptionList = new List<string>();
List<string> PnPDeviceIDList = new List<string>();
//ManagementClass PnpDeviceClass = new ManagementClass("Win32_PnpEntity");
ManagementObjectSearcher searcher = new ManagementObjectSearcher("Select * From Win32_PnpEntity WHERE ConfigManagerErrorCode = 0");
ManagementObjectCollection PnPDevices = searcher.Get();
foreach (ManagementObject item in PnPDevices)
{
if (item.Properties["Description"] !=null)
{
PnPDeviceDescriptionList.Add(item["Description"].ToString());
}
else PnPDeviceDescriptionList.Add("please work");
PnPDeviceIDList.Add(item["DeviceID"].ToString());
}
return (PnPDeviceIDList, PnPDeviceDescriptionList);
}
private void btn_PnPDevices_Click(object sender, EventArgs e)
{
(List<string> PnpDeviceIDList, List<string> PnpDeviceDescriptionList) = PnpDeviceCheck();
for (int i = 0; i < PnpDeviceDescriptionList.Count; i++)
{
txt_log.Text += PnpDeviceDescriptionList[i] + "--" + PnpDeviceIDList[i] + Environment.NewLine;
}
}
}
}