Windows 10和WMI查询更改 [英] Windows 10 and WMI Query change

查看:79
本文介绍了Windows 10和WMI查询更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用WMI查询来检测何时检测到新设备,在这种情况下是USB设备。一个创建虚拟comport的蓝牙适配器。



WMI查询字符串是为Win32_PnPEntity选择名称,状态,用于即插即用实体。



这对我来说很有用,除了Windows 10,它无法感知设备已被插入并因此被移除。



我已经搜索了这些查询的任何更改但找不到任何内容。



有谁知道在哪里可以找到不同操作系统之间的更改列表?



谢谢

解决方案

我下载了WMI Code Creator并用它来获取'Win32_PnPEntity的c#代码'使用name属性。



在WMI代码创建器中,您可以搜索name属性的属性值,但我确实获得了USB设备的列表,但是我复制了代码并将其放入我的程序中,它没有列出我想要的设备。



Bot h程序显然运行在相同的操作系统上,所以我不明白为什么它不会在我的程序中列出设备。下面的代码是我从WMI CC中提取的代码。





 使用系统; 
使用 System.Management;
使用 System.Windows.Forms;

命名空间 WMISample
{
public class MyWMIQuery
{
public static void Main()
{
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher( root \\CIMV2
SELECT * FROM Win32_PnPEntity< /跨度>);

foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine( --------------- --------------------);
Console.WriteLine( Win32_PnPEntity instance);
Console.WriteLine( ----------------- ------------------);
Console.WriteLine( 名称:{0},queryObj [ 名称]);
}
}
catch (ManagementException e)
{
MessageBox.Show( 查询WMI数据时发生错误: + e.Message);
}
}
}
}





任何想法可能是什么?


I have been using a WMI Query to detect when a new device has been detected, in this case a USB device. A Bluetooth dongle that creates a virtual comport.

The WMI Query string is "Select Name, Status from Win32_PnPEntity" for the Plug and Play entity.

This works great for me except for Windows 10, it cannot sense that the device has been inserted and therefore removed.

I have done a search for any changes to these queries but cannot find anything.

Does anyone know where I can find a list of the changes between the different operating systems?

Thanks

解决方案

I downloaded the WMI Code Creator and used it to get c# code for 'Win32_PnPEntity' using the name property.

In WMI Code creator lets you search for the property values for the name property and I did get a list for the USB device, however when I copied the code and put it in my program, it does not list the device that I want.

Both programs obviously run on the same OS and so I don't understand why it wont list the device in my program. The code below is what I extracted from WMI CC.


using System;
using System.Management;
using System.Windows.Forms;

namespace WMISample
{
    public class MyWMIQuery
    {
        public static void Main()
        {
            try
            {
                ManagementObjectSearcher searcher =
                    new ManagementObjectSearcher("root\\CIMV2",
                    "SELECT * FROM Win32_PnPEntity");

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    Console.WriteLine("-----------------------------------");
                    Console.WriteLine("Win32_PnPEntity instance");
                    Console.WriteLine("-----------------------------------");
                    Console.WriteLine("Name: {0}", queryObj["Name"]);
                }
            }
            catch (ManagementException e)
            {
                MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
            }
        }
    }
}



Any ideas what this could be?


这篇关于Windows 10和WMI查询更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆