namespace win.util;

ExitWindowsEx = ::User32.api("ExitWindowsEx","int(int uFlags,pointer dwReserved)")
SetSystemPowerState = ::Kernel32.api("SetSystemPowerState","int(int fSuspend,int fForce)")

 
exit = function( mode = 1 ){
    if(! setprivilege("SeShutdownPrivilege",true) )
		return false;
    
    
    var result; 
    select(mode){ 
        case 1 {
            //关机
            result = ExitWindowsEx(0x1/*_EWX_SHUTDOWN*/| 0x00000008/*_EWX_POWEROFF*/ |0x4/*_EWX_FORCE*/ );
        } 
        case 2 {
            //重启
            result = ExitWindowsEx(0x2/*_EWX_REBOOT*/|0x4/*_EWX_FORCE*/ );
        } 
        case 3 {
            //注销
            result = ExitWindowsEx(0x0/*_EWX_LOGOFF*/|0x4/*_EWX_FORCE*/);
        } 
        case 4 {
            //待机
            result = SetSystemPowerState( 1, 1); 
        } 
        else {
            //休眠
            result = SetSystemPowerState( 0, 0 );
        } 
    
    } 
    return result ;
}

/*intellisense(win.util)
exit() = 关机 
exit(2) = 重启
exit(3) = 注销
eixt(4) = 待机
exit(5) = 休眠
end intellisense*/
