2

C++ を使用して Windows ローカル サービスを作成しています。ウェイク タイマーが実行されているシステムで有効になっているかどうかを知る必要があります。ローカルサービスからそれを行うにはどうすればよいですか?

このスクリーンショットで丸で囲まれている設定:

ここに画像の説明を入力

4

1 に答える 1

2

以前の投稿で指摘したように、この設定はレジストリに保存されます。

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\(Current Power Scheme GUID)\(Sleep Category GUID)\(Enable AC or DC Wake Timers GUID) = 0 または 1

この設定の現在の値をコマンド ラインから取得することもできます。

powercfg.exe -q SCHEME_CURRENT SUB_SLEEP

より良いアプローチが存在すると確信していますが、これが私がこれまでに見つけたすべてです。より良いテクニックを見つけたら、投稿を更新します。

編集

次の C# コードをガイドとして使用してください。ACWakeTimerEnabled() は、有効または無効を示す 0 または 1 を返します。

 [DllImport("powrprof.dll", SetLastError = true)]
    private static extern UInt32 PowerReadACValue(
        IntPtr RootPowerKey,
        ref Guid SchemeGuid,
        ref Guid SubGroupOfPowerSettingGuid,
        ref Guid PowerSettingGuid,
        IntPtr Type,
        IntPtr Buffer,
        ref UInt32 BufferSize);

    public static int ACWakeTimerEnabled()
    {
        Guid Root = new Guid("8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c"); // High Performance GUID
        Guid Sleep = new Guid("238c9fa8-0aad-41ed-83f4-97be242c8f20"); // Sleep Subcategory GUID
        Guid WakeTimers = new Guid("bd3b718a-0680-4d9d-8ab2-e1d2b4ac806d"); // AC Wake Timers GUID
        IntPtr ptrActiveGuid = IntPtr.Zero;
        uint buffSize = 0;
        uint res = PowerReadACValue(IntPtr.Zero, ref Root, ref Sleep, ref WakeTimers, IntPtr.Zero, IntPtr.Zero, ref buffSize);
        if (res == 0)
        {
            IntPtr ptrName = IntPtr.Zero;
            try
            {
                ptrName = Marshal.AllocHGlobal((int)buffSize);
                res = PowerReadACValue(IntPtr.Zero, ref Root, ref Sleep, ref WakeTimers, IntPtr.Zero, ptrName, ref buffSize);
                byte[] ba = new byte[buffSize];
                Marshal.Copy(ptrName, ba, 0, (int)buffSize);
                return BitConverter.ToInt32(ba, 0);
            }
            finally
            {
                if (ptrName != IntPtr.Zero) Marshal.FreeHGlobal(ptrName);
            }
        }
        throw new Win32Exception((int)res, "Error reading wake timer.");
    }
于 2012-09-26T06:40:34.160 に答える