// 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 .
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
#if !SILVERLIGHT
using System.Windows.Forms;
#endif
namespace crudwork.Utilities
{
///
/// System Functions: LogOff, Restart, Shutdown, Hibernate, Standby
///
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);
///
/// Empty the System Recycle Bin
///
public static uint EmptyRecycleBin()
{
return SHEmptyRecycleBin(IntPtr.Zero, null, 0);
}
///
/// Lock the workstation
///
public static void Lock()
{
LockWorkStation();
}
///
/// Log off the user
///
///
public static void LogOff(bool force)
{
ExitWindowsEx(force ? 4 : 0, 0);
}
///
/// Reboot the system
///
public static void Reboot()
{
ExitWindowsEx(2, 0);
}
///
/// Shutdown the system
///
public static void Shutdown()
{
ExitWindowsEx(1, 0);
}
#if !SILVERLIGHT
///
/// Put the system into hibernate mode
///
public static void Hibernate()
{
Hibernate(true, true);
}
///
/// Put the system into hibernate mode
///
///
///
public static void Hibernate(bool force, bool disableWakeupEvent)
{
Application.SetSuspendState(PowerState.Hibernate, force, disableWakeupEvent);
}
///
/// Put the system into standby mode
///
public static void Standby()
{
Standby(true, true);
}
///
/// Put the system into standby mode
///
///
///
public static void Standby(bool force, bool disableWakeupEvent)
{
Application.SetSuspendState(PowerState.Suspend, force, disableWakeupEvent);
}
#endif
}
}