# terminateSession.bat
for /f %%i in ('qwinsta ^| findstr /C:">rdp-tcp#"') do set RDP_SESSION=%%i
:: Strip the >
set RDP_SESSION=%RDP_SESSION:>=%
tscon %RDP_SESSION% /dest:console
위 내용대로 작성후 .bat 확장자 파일을 만들고 원격 세션 종료
C:\Users\user>qwinsta
세션 이름 사용자 이름 ID 상태 종류 장치
services 0 디스크
>console wati 1 활성
rdp-tcp 65536 수신 대기
for {%% | %}<variable> in (<set>) do <command> [<commandlineoptions>]
tscon {<sessionID> | <sessionname>} [/dest:<sessionname>] [/password:<pw> | /password:*] [/v]
C:\Users\user>dir ^
More? /b
참고. 회사 보안정책상 화면보호기나 잠금을 해제 할 수 없을 때
GPT 선생님의 도움
@echo off
:: Change the code page to 437 (English).
chcp 437
:: Initialize the variable to store the session ID.
set RDP_SESSION=
:: Extract the session ID of the active RDP session.
for /f "tokens=3" %%i in ('qwinsta ^| findstr /C:"Active"') do set RDP_SESSION=%%i
:: Restore the code page to the original (Korean 949).
chcp 949
:: Display the extracted session ID.
echo RDP Session ID is %RDP_SESSION%
:: Switch the session to the console.
tscon %RDP_SESSION% /dest:console
:: Display completion message.
echo RDP session has been switched to the console.
:: Wait for 10 seconds before closing the CMD window.
timeout /t 10 /nobreak