1

コードに WMI を利用しようとしていますが、System.Management クラスが存在しないため使用できません。3.5 および 4 Net で試しました。何も機能しません。この問題の解決策が見つかりませんでした。これに遭遇したことがある人はいますか? もしそうなら、私が持っているのはなぜですか:

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 ネット 3.5 - ネット 4 を使用。

ここで何が欠けているのかわかりません。

4

5 に答える 5

4

System.Management.Instrumentationはクラスではなく、名前空間です。取得した using ディレクティブを考慮して、System.Management.dll への参照を取得した場合、次のようなコードを記述できるはずです。

ObjectQuery query = new ObjectQuery("...");
于 2011-10-01T18:37:04.997 に答える
1

System.Management への参照を追加しましたか? また、ターゲットにしているフレームワークのバージョンがクライアント プロファイルではないことを確認してください。

于 2011-10-01T18:35:03.847 に答える
1

System.Management.InstrumentationMSDN には、名前空間の下に非常に多くのクラスがリストされています。

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します-必ず参照を追加してください。

于 2011-10-01T18:36:01.797 に答える
1

System.Management.*.dll ファイルへの参照を追加する必要があると思います。

私のように C++ のバックグラウンドを持っている場合は、C/C++ の include ステートメントと同様に c# のステートメントを使用するという見方をしたときに、私が過去に経験したのと同じ概念上の問題を抱えていると思います。それは微妙な違いですが、数年前にリフレクターを手に入れたときに、何年にもわたる非常にわずかな混乱がようやく解消されました...

于 2011-10-01T18:36:34.830 に答える
0

プロジェクトの [参照] フォルダーを右クリックし、[参照の追加...] を選択して、[.NET] タブから [System.Management.dll] を選択します。(DLL が表示されるまでしばらく待つ必要がある場合があります。このリストは遅延ロードされます。)

また、プロジェクトのプロパティで、.NET Framework クライアント プロファイルを対象としていないことを確認してください。ほとんどの場合、完全な .NET Framework 4.0 が必要になります。

これをしないと何も見えないのはなぜですか?ややこしいことに、.NET ライブラリのアセンブリ名前空間の間に必ずしも 1 対 1 の関係があるとは限りません。

そのため、System.Management.dllアセンブリへの参照を含めなくても、System.Management 名前空間に 1 つのクラスが表示されます。これは、既に参照した他のアセンブリのいずれかに含まれています。システム コア アセンブリ自体。

System.Management 名前空間に独自のクラスを追加することで、このトリックを自分で試すことができます。

namespace System.Management
{
   public class MyClass
   {
   }
}

これは、プロジェクトのプロパティで指定されたアセンブリになりますが、名前空間 に属しますSystem.Management

名前空間名とアセンブリ名の関係を壊すと非常に混乱するので注意してください。

于 2011-10-01T18:55:59.970 に答える