System Functions: LogOff, Restart, Shutdown, Hibernate, Standby : System Object Method « Development Class « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Development Class » System Object MethodScreenshots 
System Functions: LogOff, Restart, Shutdown, Hibernate, Standby
 
// crudwork
// Copyright 2004 by Steve T. Pham (http://www.crudwork.com)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with This program.  If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
#if !SILVERLIGHT
using System.Windows.Forms;
#endif

namespace crudwork.Utilities
{
    /// <summary>
    /// System Functions: LogOff, Restart, Shutdown, Hibernate, Standby
    /// </summary>
    public static class SystemFunctions
    {
        [DllImport("user32.dll")]
        private static extern void LockWorkStation();

        [DllImport("user32.dll")]
        private static extern int ExitWindowsEx(int uFlags, int dwReason);

        private enum RecycleFlags : uint
        {
            SHERB_NOCONFIRMATION = 0x00000001,
            SHERB_NOPROGRESSUI = 0x00000002,
            SHERB_NOSOUND = 0x00000004
        }

        [DllImport("Shell32.dll", CharSet = CharSet.Unicode)]
        private static extern uint SHEmptyRecycleBin(IntPtr hwnd, string pszRootPath, RecycleFlags dwFlags);



        /// <summary>
        /// Empty the System Recycle Bin
        /// </summary>
        public static uint EmptyRecycleBin()
        {
            return SHEmptyRecycleBin(IntPtr.Zero, null, 0);
        }

        /// <summary>
        /// Lock the workstation
        /// </summary>
        public static void Lock()
        {
            LockWorkStation();
        }

        /// <summary>
        /// Log off the user
        /// </summary>
        /// <param name="force"></param>
        public static void LogOff(bool force)
        {
            ExitWindowsEx(force ? 00);
        }

        /// <summary>
        /// Reboot the system
        /// </summary>
        public static void Reboot()
        {
            ExitWindowsEx(20);
        }

        /// <summary>
        /// Shutdown the system
        /// </summary>
        public static void Shutdown()
        {
            ExitWindowsEx(10);
        }

#if !SILVERLIGHT
        /// <summary>
        /// Put the system into hibernate mode
        /// </summary>
        public static void Hibernate()
        {
            Hibernate(true, true);
        }

        /// <summary>
        /// Put the system into hibernate mode
        /// </summary>
        /// <param name="force"></param>
        /// <param name="disableWakeupEvent"></param>
        public static void Hibernate(bool force, bool disableWakeupEvent)
        {
            Application.SetSuspendState(PowerState.Hibernate, force, disableWakeupEvent);
        }

        /// <summary>
        /// Put the system into standby mode
        /// </summary>
        public static void Standby()
        {
            Standby(true, true);
        }

        /// <summary>
        /// Put the system into standby mode
        /// </summary>
        /// <param name="force"></param>
        /// <param name="disableWakeupEvent"></param>
        public static void Standby(bool force, bool disableWakeupEvent)
        {
            Application.SetSuspendState(PowerState.Suspend, force, disableWakeupEvent);
        }
#endif
    }
}

   
  
Related examples in the same category
1.illustrates some of the System.Object class methodsillustrates some of the System.Object class methods
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.