View Single Post
Old 2008-05-10, 01:06   #10 (permalink)
MoPhat
MP Donator
 
MoPhat's Avatar
 
Join Date: Jun 2007
Location: Berg, Switzerland
Age: 35
Posts: 644
Thanks: 4
Thanked 40 Times in 10 Posts

Country:

My System

Default

Hi, i have now tryed some combinations and found one working solution, i send this Bavarian too:

Code:
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace PowerApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        [DllImport("Kernel32.dll", EntryPoint = "SetThreadExecutionState", CharSet = CharSet.Auto, SetLastError = true)]
        private extern static EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE state);

        [Flags]
        public enum EXECUTION_STATE : uint
        {
            ES_AWAYMODE_REQUIRED = 0x00000040,
            ES_CONTINUOUS = 0x80000000,
            ES_DISPLAY_REQUIRED = 0x00000002,
            ES_SYSTEM_REQUIRED = 0x00000001,
            ES_USER_PRESENT = 0x00000004
         }

        private void Form1_Load(object sender, EventArgs e)
        {

            try
            {
                SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS | EXECUTION_STATE.ES_SYSTEM_REQUIRED | EXECUTION_STATE.ES_AWAYMODE_REQUIRED);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            
        }
    }
}
The only thing is that in the windows power settings should disabled that a password is needed for recovery...

MoPhat is offline   Reply With Quote
2 Users Say Thank You: