c#系统.管理只有1个班

本文关键字:1个班 管理 系统 | 更新日期: 2023-09-27 18:10:08

我一直在尝试使用WMI为我的代码,我不能使用系统。因为没有管理类课程。我在3.5和4net上都试过。没有什么工作。我还没有找到解决这个问题的办法,不知道你们有没有遇到过这种情况?如果是这样,为什么我只有:

System.Management.Instrumentation

下面的using块:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Management;
using System.IO;
using System.Security.Permissions;
using Microsoft.Win32;
using System.Collections;
using System.Management.Instrumentation;

信息:

Visual Studio 2010 Ultimate使用net 3.5 - net 4.

不知道我在这里错过了什么

c#系统.管理只有1个班

System.Management.Instrumentation不是一个,它是一个名称空间。给定您已经得到的using指令,如果您已经得到了对System.Management.dll的引用,您应该能够编写如下代码:

ObjectQuery query = new ObjectQuery("...");

MSDN在System.Management.Instrumentation命名空间下列出了相当多的类:

<>之前DefaultManagementInstaller类DefaultManagementProjectInstaller类IEvent接口IgnoreMemberAttribute类IInstance接口实例类InstanceNotFoundException类仪器仪表类InstrumentationBaseException类InstrumentationClassAttribute类InstrumentationException类InstrumentationManager类InstrumentationType枚举InstrumentedAttribute类ManagedCommonProvider类ManagedNameAttribute类ManagementBindAttribute类ManagementCommitAttribute类ManagementConfigurationAttribute类ManagementConfigurationType枚举ManagementCreateAttribute类ManagementEntityAttribute类ManagementEnumeratorAttribute类ManagementHostingModel枚举ManagementInstaller类ManagementKeyAttribute类ManagementMemberAttribute类ManagementNameAttribute类ManagementNewInstanceAttribute类ManagementProbeAttribute类ManagementQualifierAttribute类ManagementQualifierFlavors枚举ManagementReferenceAttribute类ManagementRemoveAttribute类ManagementTaskAttribute类WmiConfigurationAttribute类WmiProviderInstallationException类之前

这些存在于System.Management.dll中-确保您添加了对它的引用。

我相信你需要添加对System.Management.*.dll文件的引用。

如果你像我一样有c++背景,我猜你会有和我过去一样的概念问题,当时我认为在c#中使用语句类似于在C/c++中包含语句。这是一个微妙的差异,但它导致我多年来非常轻微的困惑,最终在几年前我掌握了反射器后才得以解决…

是否添加了System.Management的引用?还要确保你的目标框架版本不是客户端配置文件。

右键单击项目的References文件夹,然后选择Add Reference…从。net选项卡中选择System.Management.dll。(您可能需要等待一段时间才能显示DLL,此列表是惰性加载的。)

同时,确保在项目属性中你的目标不是。net Framework客户端配置文件:你很可能需要完整的。net Framework 4.0。

为什么你不这样做就能看到任何东西?相当令人困惑的是,. net库中的程序集命名空间之间不一定是一对一的关系。

因此,即使您不包含对System. management .dll 程序集的引用,您仍然会在System中看到一个类。管理名称空间——它包含在您已经引用的其他程序集之一中,或者系统核心程序集本身。

你可以把你自己的类添加到系统中来尝试这个技巧。管理名称空间:

namespace System.Management
{
   public class MyClass
   {
   }
}

这将在项目属性中命名的程序集中结束,但将属于命名空间 System.Management

注意,打破命名空间名称和程序集名称之间的关系会让人非常困惑,所以不要这样做!