示例#1
0
        /// <summary>
        /// コンピューターを強制的にシャットダウン・再起動・ログオフ・スタンバイ・休止状態にします。
        /// </summary>
        /// <param name="shutDownSwitch"></param>
        public static void ShutDown(ShutDownSwitch shutDownSwitch)
        {
            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                adjustToken();
            }

            EWX ewx = EWX.FORCE;

            switch (shutDownSwitch)
            {
            case ShutDownSwitch.PowerOff:
                ewx |= EWX.POWEROFF;
                break;

            case ShutDownSwitch.Reboot:
                ewx |= EWX.REBOOT;
                break;

            case ShutDownSwitch.LogOff:
                ewx |= EWX.LOGOFF;
                break;

            case ShutDownSwitch.StandBy:
            case ShutDownSwitch.Hibernate:
                bool hibernate = (shutDownSwitch == ShutDownSwitch.Hibernate);
                PowrProf.SetSuspendState(hibernate, true, true);
                return;

            default:
                throw new ArgumentException();
            }

            User32.ExitWindowsEx(ewx, 0);
        }
        /// <summary>
        /// コンピューターを強制的にシャットダウン・再起動・ログオフ・スタンバイ・休止状態にします。
        /// </summary>
        /// <param name="shutDownSwitch"></param>
        public static void ShutDown(ShutDownSwitch shutDownSwitch)
        {
            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                adjustToken();
            }

            EWX ewx = EWX.FORCE;

            switch (shutDownSwitch)
            {

            case ShutDownSwitch.PowerOff:
                ewx |= EWX.POWEROFF;
                break;

            case ShutDownSwitch.Reboot:
                ewx |= EWX.REBOOT;
                break;

            case ShutDownSwitch.LogOff:
                ewx |= EWX.LOGOFF;
                break;

            case ShutDownSwitch.StandBy:
            case ShutDownSwitch.Hibernate:
                bool hibernate = (shutDownSwitch == ShutDownSwitch.Hibernate);
                PowrProf.SetSuspendState(hibernate, true, true);
                return;

            default:
                throw new ArgumentException();
            }

            User32.ExitWindowsEx(ewx, 0);
        }