
namespace sys

ExitWindowsEx = ::User32.api("ExitWindowsEx","int(int uFlags,pointer dwReserved)")
SetSystemPowerState = ::Kernel32.api("SetSystemPowerState","int(int fSuspend,int fForce)")
 
shutdown = 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 ;
}
restart = function(){
	return shutdown(2)
} 
logoff = function(){
	return shutdown(3)	
}
standby= function(){
	return shutdown(4)	
}
self.sleep= function(){
	return shutdown(5)	
}
/*intellisense(sys)
shutdown()=关机
restart()=重启
logoff()=注销
standby()=待机
sleep()=休眠
end intellisense*/
