programing tip

bat 파일을 통해 Windows를 종료, 다시 시작 또는 로그 오프하려면 어떻게합니까?

itbloger 2020. 10. 2. 21:47
반응형

bat 파일을 통해 Windows를 종료, 다시 시작 또는 로그 오프하려면 어떻게합니까?


워크 스테이션에 들어가기 위해 원격 데스크톱 연결사용 하고 있습니다. 하지만이 환경에서는 시작 메뉴의 전원 옵션을 사용할 수 없습니다. 종료하거나 다시 시작하는 다른 방법이 필요합니다.

명령 줄을 통해 컴퓨터의 전원 상태를 어떻게 제어합니까?


shutdown명령 을 사용하는 가장 일반적인 방법 은 다음과 같습니다.

  • shutdown -s — 종료합니다.
  • shutdown -r — 다시 시작합니다.
  • shutdown -l — 로그 오프합니다.
  • shutdown -h — 최대 절전 모드입니다.

    참고 : 사용자가 -h"도움말"을 의미 한다고 생각하는 일반적인 함정이 있습니다 ( shutdown.exe"최대 절전 모드"를 의미하는를 제외하고 다른 모든 명령 줄 프로그램에 대해 수행됨). 그런 다음 shutdown -h컴퓨터 를 실행 하고 실수로 컴퓨터를 끕니다. 조심하세요.

  • shutdown -i— "대화 형 모드". 작업을 수행하는 대신 GUI 대화 상자를 표시합니다.

  • shutdown -a — 이전 종료 명령을 중단합니다.

위의 명령은 다음 추가 옵션과 결합 할 수 있습니다.

  • -f— 프로그램을 강제 종료합니다. 종료 프로세스가 중단되는 것을 방지합니다.
  • -t <seconds>— 종료까지의 시간을 설정합니다. -t 0즉시 종료하는 데 사용 합니다.
  • -c <message>— 종료 메시지를 추가합니다. 메시지는 이벤트 로그에 기록됩니다.
  • -y — 모든 종료 쿼리에 "예"응답을 강제합니다.

    참고 : 이 옵션은 공식 문서에 문서화되어 있지 않습니다. 이 StackOverflow 사용자 가 발견했습니다 .


이 질문과 함께 다른 정말 좋은 답변도 언급하고 싶습니다. 여기에는 특별한 순서가 없습니다.


원격 시스템에있는 경우 -f 옵션을 추가하여 강제 로 재부팅 할 수도 있습니다 . 그렇지 않으면 세션이 닫히고 완고한 앱으로 인해 시스템이 중단 될 수 있습니다.

즉시 재부팅을 원할 때마다 이것을 사용합니다.

shutdown -t 0 -r -f

좀 더 친근한 "시간 제공"옵션을 위해 다음을 사용할 수 있습니다.

shutdown -t 30 -r

주석에서 볼 수 있듯이 -f는 시간 제한을 의미합니다.

Brutus 2006은 이러한 옵션에 대한 GUI를 제공하는 유틸리티입니다.


아무도 -m원격 종료 옵션을 언급하지 않았습니다 .

shutdown -r -f -m \\machinename

또한:

  • -r매개 변수는 재부팅을 유발합니다 (물리적으로 시작하는 것이 어려울 수 있으므로 일반적으로 원격 시스템에서 원하는 것입니다).
  • -f매개 변수 옵션은 재부팅을 강제로.
  • 물론 원격 시스템을 종료하려면 적절한 권한이 있어야합니다.

원문 답변 : 2008 년 10 월

당신은 또한 모든 " rundll32.exe shell32.dll" 세리 :

(아래 업데이트 참조)

  • rundll32.exe user.exe,**ExitWindows** [윈도우 빠른 종료]
  • rundll32.exe user.exe,**ExitWindowsExec** [Windows 다시 시작]

    rundll32.exe shell32.dll,SHExitWindowsEx n
    

어디 n를 의미합니다 :

  • 0- LOGOFF
  • 1 - SHUTDOWN
  • 2- REBOOT
  • 4- FORCE
  • 8- POWEROFF

(결합 가능-> 6 = 2 + 4 FORCE REBOOT)


2015 년 4 월 업데이트 (6 년 이상 후) :

1800 정보 는 주석에서 친절하게 지적합니다 .

rundll32.exe이 목적으로 사용하지 마십시오 . 명령 줄에서 전달한 함수에 매우 구체적인 메서드 서명이있을 것으로 예상합니다. 이는의 메서드 서명과 일치하지 않습니다 ExitWindows.

Raymond CHEN 은 다음과 같이 썼습니다.

The function signature required for functions called by rundll32.exe is:

void CALLBACK ExitWindowsEx(HWND hwnd, HINSTANCE hinst,
       LPSTR pszCmdLine, int nCmdShow);

That hasn't stopped people from using rundll32 to call random functions that weren't designed to be called by rundll32, like user32 LockWorkStation or user32 ExitWindowsEx.

(oops)

The actual function signature for ExitWindowsEx is:

BOOL WINAPI ExitWindowsEx(UINT uFlags, DWORD dwReserved);

And to make it crystal-clear:

Rundll32 is a leftover from Windows 95, and it has been deprecated since at least Windows Vista because it violates a lot of modern engineering guidelines.


Another small tip: when going the batch file route, I like to be able to abort it in case I run it accidentally. So the batch file invokes the shutdown but leaves you at the command prompt afterwards.

@echo off
echo Shutting down in 10 seconds. Please type "shutdown /a" to abort.
cmd.exe /K shutdown /f /t 10 /r

Plus, since it's on a timer, you get about the same thrill as you do when hunting in The Oregon Trail.


When remoted into a machine (target is Windows XP anyway; I am not sure about target Windows Vista), although Shutdown on the start menu is replaced by Disconnect Session or something like that, there should be one called 'Windows Security' which also does the same thing as Ctrl + Alt + End as pointed to by Owen.


You're probably aware of this, but just in case: it's much easier to just type shutdown -r (or whatever command you like) into the "Run" box and hit enter.

Saves leaving batch files lying around everywhere.


I would write this in Notepad or WordPad for a basic logoff command:

@echo off
shutdown -l

This is basically the same as clicking start and logoff manually, but it is just slightly faster if you have the batch file ready.


I'm late to the party, but did not see this answer yet. When you don't want to use a batch file or type the command. You can just set focus to the desktop and then use Alt + F4.

Windows will ask you what you want to do, select shutdown or restart.

For screenshots and even a video, see: https://tinkertry.com/how-to-shutdown-or-restart-windows-over-rdp

참고URL : https://stackoverflow.com/questions/162304/how-do-i-shutdown-restart-or-log-off-windows-via-a-bat-file

반응형