윈도우 명령어로 시스템 종료하는 방법

MintheWiki

Jump to: navigation, 찾기
윈도우 명령어로 시스템 종료하는 방법
BOOL IsWindowsNT()
{
 OSVERSIONINFO verInfo;
 verInfo.dwOSVersionInfoSize = sizeof(verInfo);
 GetVersionEx(&verInfo) ;
 switch(verInfo.dwPlatformId)
 {
 case VER_PLATFORM_WIN32_WINDOWS:
 return FALSE;
 case VER_PLATFORM_WIN32_NT:
 return TRUE;
 }
 return FALSE;
}
 
BOOL AdjustSystemForShutdown()
{
 if(IsWindowsNT() == FALSE)
 return FALSE ;
 
 HANDLE hTk;
 TOKEN_PRIVILEGES tp;
 
 /* Get a token for this process. */
 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hTk))
 return FALSE;
 
 /* Get the LUID for the shutdown privilege. */
 LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tp.Privileges[0].Luid);
 
 tkp.PrivilegeCount = 1; /* one privilege to set */
 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
 
 /* Get the shutdown privilege for this process. */
 return AdjustTokenPrivileges(hTk, FALSE, &tp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
}
 
 
 
//이렇게 해서, 권한 변경에 성공하면 ExitWindowsEx, SetSystemPowerState 함수로 자신이 원하는 대로 시스템을 컨트롤 할 수 있습니다.
 
 // Windows 2000, XP 
 // Log Off
 ExitWindowsEx(EWX_LOGOFF|EWX_FORCEIFHUNG , SHTDN_REASON_FLAG_PLANNED ); 
 
 // Shutdown
 ExitWindowsEx(EWX_POWEROFF|EWX_FORCEIFHUNG , SHTDN_REASON_FLAG_PLANNED ); // NT
 
 // Reboot
 ExitWindowsEx(EWX_REBOOT|EWX_FORCEIFHUNG,SHTDN_REASON_FLAG_PLANNED );
 
 // Suspend
 SetSystemPowerState(TRUE, TRUE ); // force suspend
 
 // Windows 95, 98, ME
 // Log Off
 ExitWindowsEx(EWX_LOGOFF|EWX_FORCE , 0 ); 
 
 // Shutdown
 ExitWindowsEx(EWX_SHUTDOWN|EWX_FORCE, 0 ); // Windows 98, Windows ME
 
 // Reboot
 ExitWindowsEx(EWX_REBOOT|EWX_FORCE, 0 );
 
 // Suspend
 SetSystemPowerState(TRUE, TRUE ); // force suspend


  • vb script(제약이 있음)
Public Declare Function SetSuspendState Lib "Powrprof.dll" _
Alias "SetSuspendState" (ByVal Hibernate As Integer, _
ByVal ForceCritical As Integer, _
ByVal DisableWakeEvent As Integer) As Integer


끄기: %windir%₩System32₩shutdown.exe -s
재부팅: %windir%₩System32₩shutdown.exe -r
로그오프: %windir%₩System32₩shutdown.exe -l
대기모드: %windir%₩System32₩rundll32.exe powrprof.dll,SetSuspendState
최대 절전모드: %windir%₩System32₩rundll32.exe powrprof.dll,SetSuspendState Hibernate
  • 목록