2010-12-14 22 views
0

私は、C#でWindowsの電源プランを管理するソフトウェアをやっており、電源プランを取得し、その設定をManagementObjetで簡単に設定できます。しかし、私は新しいPower Planを作成したい、つまり新しいWMIオブジェクトを作成したいのですが、その方法はわかりません。WMIオブジェクトの作成/挿入方法は?

作成方法はわかりますか?

答えて

1

これはWMIでは実行できません。 hereのように、Power Scheme Management用のWin32 APIを使用してプランを作成し、WMIを使用してそれを監視/管理することができます。

電源設定を作成するには、まず、あなたが上にあなたの新しい スキームをベースにしたい スキームのGUIDを指定して、PowerDuplicateScheme 機能を使用して することにより、既存のスキームを複製 する必要があります。組み込みのスキーム の1つをコピーし、必要に応じて の電源設定を変更する必要があります。

+0

ため

using System.Runtime.InteropServices; [DllImport("powrprof.dll", EntryPoint = "PowerDuplicateScheme", SetLastError = true)] public static extern UInt32 PowerDuplicateScheme(IntPtr RootPowerKey, ref Guid SrcSchemeGuid, ref IntPtr DstSchemeGuid); public static Guid createNewPowerPlan() { Guid result = new Guid(); IntPtr RetrPointer = IntPtr.Zero; // Attempt to duplicate the 'Balanced' Power Scheme. NativeMethods.PowerDuplicateScheme(IntPtr.Zero, ref VISA_PM_BASIC_SCHEMES.BALANCED, ref RetrPointer); if (RetrPointer != IntPtr.Zero) { // Function returns a pointer-to-memory, marshal back to our Guid variable. result = (Guid)Marshal.PtrToStructure(RetrPointer, typeof(Guid)); } return result; } 

おかげで私もこの方法を見つけました: – fghoffmann

0

今では働いている...私はそれを行ってどのように怒鳴る従ってください:あなたの助け

関連する問題