Hibernate and Suspend

hi ppl,,, i have an application that will be able to shut down system, rboot hibernate and suspend.. i allready worked out the hibernate and suspend.. but i just dont find the way to hibernate and suspend ( actually i dont know if those 2 are diferent things lol) ..

so does anybody know how to do it

thx

mig16


Answer this question

Hibernate and Suspend

  • simon_p


    thanks,, everything compile but this:


    protected bool CheckEntryPoint(string library, string method)
            {
                IntPtr libPtr = LoadLibrary(library);
                if (!libPtr.Equals(IntPtr.Zero))
                {
                    if (!GetProcAddress(libPtr, method).Equals(IntPtr.Zero))
                    {
                        FreeLibrary(libPtr);
                        return true;
                    }

                    FreeLibrary(libPtr);
                }
                return false;
            }

     


    it dont find what is GetProcAddress ... is there any reference i should add or a namespace   and by the way... how do u add code to ur post .. i dont find a way to add formatted code to my post :P

    thx

    mig16

  • Chris.NET

    Youssef, thanks for you reply. Indeed, this is a easier way but only works in .NET 2.x, here is the MSDN documentation: Application.SetSuspendState.


  • Glenn Davis

    i need to know how to do it

    thx

    mig16

  • Shilpa Shashitej

    Actually there is an easier way and works like a charm

    Application.SetSuspendState(PowerState.Hibernate, ...)

    or if you want to go to standby

    Application.SetSuspendState(PowerState.Suspend, ...)


  • Claude M

    Sorry, you need to use p/invoke for the GetProcAddress. Here is the signature:


    [ DllImport( "kernel32.dll", EntryPoint="GetProcAddress", CharSet=CharSet.Ansi ) ]
    private static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName);

    For the code format question, you can use the code tag (remove spaces):

    [ code language="c#" ]...[ /code ]



  • Mani Govindan

    Hi!

    Hybernate will save whole memory content on disk and turn off computer. When you turn computer on - it will read memory from disk and start working as if you don't go away.

    Suspend will keep memory alive and force most hardware to go to low power consumption mode. When user activate computer (key event or mouse or other external device) - power restored to all systems and computer ready to use.

    Difference is obvious - hybernate is slower, but more safe (you can turn power off); suspend is faster, but power stays on.

    Does it help or you need some more info



  • Rogerio Sobreira

    You can set the computer in Suspend or Hibernate state with the SetSuspendState method of the powrproff.dll:


    class Class1
    {
        [ DllImport( "kernel32.dll", EntryPoint="FreeLibrary", CharSet=CharSet.Ansi )]
        private static extern int FreeLibrary(IntPtr hLibModule);

        [ DllImport( "kernel32.dll", EntryPoint="LoadLibraryA", CharSet=CharSet.Ansi )]
        private static extern IntPtr LoadLibrary(string lpLibFileName);

        [DllImport( "powrprof.dll", EntryPoint="SetSuspendState", CharSet=CharSet.Ansi )]
        private static extern int SetSuspendState(int Hibernate, int ForceCritical, int DisableWakeEvent);
       
        public static void SuspendSystem( bool force )
        {
            if (!CheckEntryPoint("powrprof.dll", "SetSuspendState"))
            {
                throw new PlatformNotSupportedException("The SetSuspendState method is not supported on this system!");
            }

            int forceValue = ( force 1 : 0 );
            SetSuspendState(0, forceValue, 0);
        }
       
        public static void HibernateSystem( bool force )
        {
            if (!CheckEntryPoint("powrprof.dll", "SetSuspendState"))
            {
                throw new PlatformNotSupportedException("The SetSuspendState method is not supported on this system!");
            }

            int forceValue = ( force 1 : 0 );
            SetSuspendState(1, forceValue, 0);
        }
       
        protected static bool CheckEntryPoint( string library , string method )
        {
            IntPtr  libPtr = LoadLibrary( library );
            if( !libPtr.Equals( IntPtr.Zero ) )
            {
                if(! GetProcAddress( libPtr, method ).Equals( IntPtr.Zero ) )
                {
                    FreeLibrary( libPtr );
                    return true;
                }

                FreeLibrary( libPtr );
            }
            return false;
        }
    }

     




  • Hibernate and Suspend