Exemplo n.º 1
0
        public static int PowerSchemeSetLidActionShell(ref Guid powerScheme, LidAction value)
        {
            StringBuilder stringBuilder = new StringBuilder("powercfg -SETACVALUEINDEX");

            stringBuilder.Append(" " + powerScheme.ToString());
            stringBuilder.Append(" " + GUID_SYSTEM_BUTTON_SUBGROUP.ToString());
            stringBuilder.Append(" " + LID_ACTION.ToString());
            stringBuilder.Append(" " + (int)value);

            Shell.ShellExecuteCommand(stringBuilder.ToString(), false);

            stringBuilder = new StringBuilder("powercfg -SETDCVALUEINDEX");

            stringBuilder.Append(" " + powerScheme.ToString());
            stringBuilder.Append(" " + GUID_SYSTEM_BUTTON_SUBGROUP.ToString());
            stringBuilder.Append(" " + LID_ACTION.ToString());
            stringBuilder.Append(" " + (int)value);

            Shell.ShellExecuteCommand(stringBuilder.ToString(), false);

            stringBuilder = new StringBuilder("powercfg -SETACTIVE");
            stringBuilder.Append(" " + powerScheme.ToString());

            Shell.ShellExecuteCommand(stringBuilder.ToString(), false);

            return(0);
        }
Exemplo n.º 2
0
        public static void PowerActiveSchemeSetLidAction(LidAction lidAction)
        {
            IntPtr activeGuidPtr = IntPtr.Zero;

            if (PowerGetActiveScheme(IntPtr.Zero, ref activeGuidPtr) == 0)
            {
                var tmpGuid = (Guid)Marshal.PtrToStructure(activeGuidPtr, typeof(Guid));
                PowerSchemeSetLidAction(ref tmpGuid, lidAction);
            }
        }
Exemplo n.º 3
0
        public static uint PowerSchemeSetLidAction(ref Guid powerScheme, LidAction value)
        {
            uint resDC, resAC;

            resDC = PowerWriteDCValueIndex(IntPtr.Zero, ref powerScheme,
                                           ref GUID_SYSTEM_BUTTON_SUBGROUP,
                                           ref LID_ACTION, (uint)value);

            resAC = PowerWriteACValueIndex(IntPtr.Zero, ref powerScheme,
                                           ref GUID_SYSTEM_BUTTON_SUBGROUP,
                                           ref LID_ACTION, (uint)value);

            if (resDC == 0 && resAC == 0)
            {
                resAC = PowerSetActiveScheme(IntPtr.Zero, ref powerScheme);
            }

            return(resAC);
        }
Exemplo n.º 4
0
        public static uint PowerSchemeGetLidAction(ref Guid powerScheme, ref LidAction value)
        {
            uint res;

            //Get the Power Settings
            Guid actionGuid = Guid.Empty;
            uint index      = 0;
            uint BufferSize = Convert.ToUInt32(Marshal.SizeOf(typeof(Guid)));

            while (PowerEnumerate(IntPtr.Zero, ref powerScheme, ref GUID_SYSTEM_BUTTON_SUBGROUP,
                                  18, index, ref actionGuid, ref BufferSize) == 0)
            {
                /* Search for lid action by Guid */
                if (actionGuid != LID_ACTION)
                {
                    index++;
                    continue;
                }

                uint   size = 4;
                IntPtr temp = IntPtr.Zero;
                int    type = 0;
                res = PowerReadACValue(IntPtr.Zero, ref powerScheme, IntPtr.Zero,
                                       ref actionGuid, ref type, ref temp, ref size);

                if (res != 0)
                {
                    /* error handling */
                    return(res);
                }

                value = (LidAction)temp;
                return(0);
            }

            return(2);
        }