Exemplo n.º 1
0
        public static void ExitSystem(EWX_ENUM exval)
        {
            TOKEN_PRIVILEGES tp    = new TOKEN_PRIVILEGES();
            TOKEN_PRIVILEGES tpOld = new TOKEN_PRIVILEGES();
            LUID             luid  = new LUID();


            LookupPrivilegeValue(null, "SeShutdownPrivilege", ref luid);
            int processHandle = GetCurrentProcess();
            int TokenHandle   = 0;

            OpenProcessToken(processHandle, 0x00000020 | 0x00000008, ref TokenHandle);

            tp.PriviledgeCount = 1;
            tp.Attributes      = 0x00000002;
            tp.Luid            = luid;


            int tpsz = Marshal.SizeOf(tp);

            tpsz = AdjustTokenPrivileges(TokenHandle, 0, ref tp, tpsz, 0, 0);
            //ExitWindowEx(, 0);
            ExitWindowsEx((int)exval, 0);
            //  ExitWindow((int)exval, 0);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Shuts down the machine according the given value.
        /// </summary>
        /// <param name="ewx_value">Set of flags defined in EWX_ENUM</param>
        public static void ExitSystem(EWX_ENUM ewx_value)
        {
            TOKEN_PRIVILEGES tp = new TOKEN_PRIVILEGES();
            LUID luid = new LUID();

            LookupPrivilegeValue(null, "SeShutdownPrivilege", ref luid);
            int processHandle = GetCurrentProcess();
            int tokenHandle = 0;
            OpenProcessToken(processHandle, 0x00000020 | 0x00000008, ref tokenHandle);

            tp.PriviledgeCount = 1;
            tp.Attributes = 0x00000002;
            tp.Luid = luid;

            int tpsz = Marshal.SizeOf(tp);
            AdjustTokenPrivileges(tokenHandle, 0, ref tp, tpsz, 0, 0);
            ExitwindowsEx((int)ewx_value, 0);
        }