.NETアプリケーションにリモートオートメーションを付ける
WMIは……大げさかな。
http://msdn.microsoft.com/library/ja/cpguide/html/cpconManagingApplicationsUsingWMI.asp
後でここ見ながらサンプルかいてみるー
WMI
現在の制限事項
現在のバージョンの System.Management.Instrumentation では、次の WMI 機能をサポートしていません。この制限事項はマネージ コードで実装されたオブジェクトにだけ適用されます。ネイティブ C++ WMI プロバイダを通じて公開されたオブジェクトではこれらの機能を公開でき、System.Management クラスを通じてマネージ コードからアクセスできます。
System.Management 名前空間と System.Management.Instrumentation 名前空間
- 実装されたオブジェクトは、書き込み可能なプロパティまたはメソッドを公開できません。
- 実装されたオブジェクトの修飾子の作成はサポートされていません。
- 実装されたオブジェクトのプロパティはキーとして定義できません。
にゃーす。これじゃstopできないじゃないか。
以下サンプル。実行前にInstallUtilでWMIに登録。ただし、InstallUtil /u してもWMIの登録は削除されない。なんじゃそりゃ。
using System; using System.Management.Instrumentation; using System.Threading; [assembly:Instrumented(@"root\FooBar\Counter")] [System.ComponentModel.RunInstaller(true)] public class MyInstaller : DefaultManagementProjectInstaller {} [InstrumentationClass(InstrumentationType.Instance)] public class Counter { volatile bool stop = false; volatile int counter = 0; public int Count { get {return counter;} } [IgnoreMember()] public void Service() { Instrumentation.Publish(this); while (!stop) { counter++; Thread.Sleep(10000); } Instrumentation.Revoke(this); } [IgnoreMember()] public static void Main() { Counter c = new Counter(); c.Service(); } }
wbemtest.exeでroot\FooBar\Counter名前空間のクラスを見てみたところ。