WMI代码创建者Bitlocker状态 - 我在哪里出错? [英] WMI Code Creator for Bitlocker Status - where did i go wrong?

查看:406
本文介绍了WMI代码创建者Bitlocker状态 - 我在哪里出错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用WMI代码创建者,代码看起来从应用程序。不过,出现我的代码内部的错误,我似乎不能动摇。我应该有一个参考这个工作吗?如果是,我可以在哪里得到它?

I am working with the WMI Code Creator and the code looks to work properly from the app. HOWEVER, It comes up with errors internal of my code that I cant seem to shake. Am I supposed to have a reference for this to work? if so where can I get it?

    public class MyWMIQuery
    {
        public static void Main()
        {
            try
            {
                ManagementObjectSearcher searcher =
                    new ManagementObjectSearcher("root\\CIMV2\\Security\\MicrosoftVolumeEncryption",
                    "SELECT * FROM Win32_EncryptableVolume");

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



(点击查看大图)

推荐答案

如果您在MSDN中搜索 ManagementObjectSearcher ,您将获得此页面。在.NET类的每个MSDN页面上,您将在页面顶部看到两条信息。

If you search the MSDN for ManagementObjectSearcher you get this page. On every MSDN page for a .NET class you will see two pieces of information at the top of the page.


命名空间:System.Management

程序集:System.Management(在System.Management.dll中)

Namespace: System.Management
Assembly: System.Management (in System.Management.dll)

第一行告诉您,您需要使用System.Management添加; 或执行 System.Management.ManagementObjectSearcher 如果你想引用该对象。

The first line tells you that you need to add using System.Management; or do System.Management.ManagementObjectSearcher if you want to reference the object.

第二行告诉你项目必须引用文件 System.Management.dll 为您的代码能够找到该类。如果您在添加参考对话框中进行搜索,则需要查找系统管理(括号内的部分)在列表中。

The second line tells you your project must reference the file System.Management.dll for your code to be able to find the class. If you search in the Add Reference Dialog you need to look for System.Management (the part outside of the parenthesis) in the list.

第二个您的问题的一部分是您的项目中有一个名为 ComplianceGuide.ManagmentObject 的类,Visual Studio正在挑选该引用而不是 System.Management.ManagementObject ,替换你的foreach与

The second part of your problem is you have a class called ComplianceGuide.ManagmentObject in your project and Visual Studio is picking that reference up instead of System.Management.ManagementObject, replace your foreach with

foreach (System.Management.ManagementObject queryObj in searcher.Get())

强制它使用正确的类。

这篇关于WMI代码创建者Bitlocker状态 - 我在哪里出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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