Last active
December 9, 2021 12:01
-
-
Save NotoriousPyro/7fbe54ca75fbea98cf18b44e982d2355 to your computer and use it in GitHub Desktop.
RDP Session Shadow Batch file. Accepts --noping as a parameter. Works well with RDP Wrapper. Should only be used with Windows 10 onwards.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ECHO OFF | |
MODE CON:COLS=80 LINES=40 | |
COLOR 1A | |
SETLOCAL EnableDelayedExpansion | |
:ENTRY | |
CLS | |
CALL :PRINTBAR | |
ECHO ^| RDP Session Shadow Version 2.0 ^| | |
ECHO ^| By Craig Crawford ^| | |
ECHO ^|------------------------------------------------------------------------------^| | |
ECHO ^| This is designed to be used with: ^| | |
ECHO ^| * Windows 10 / 2016 and above, ^| | |
ECHO ^| * RDP Wrapper Library: https://github.com/stascorp/rdpwrap ^| | |
CALL :PRINTBAR | |
IF [%1]==[--noping] ( | |
ECHO ^| --noping switch enabled. The remote host will not be probed by echo requests ^| | |
ECHO ^| before attemping to connect. ^| | |
CALL :PRINTBAR | |
SET NOPING=TRUE | |
) | |
SET /P PC="Enter PC: " | |
CALL :PRINTBAR | |
SET COUNT=0 | |
ECHO Attempting to connect to %PC%... | |
IF [%NOPING%]==[TRUE] GOTO NOPING | |
PING %PC% -n 1 -w 100 | FIND "Ping request could not find host %PC%" > NUL | |
IF "%ERRORLEVEL%" EQU "0" GOTO FAILED_NOHOST | |
:PING | |
SET /A COUNT+=1 | |
IF "%COUNT%" GEQ "5" GOTO FAILED_NOECHO | |
ECHO Attempting to connect to %PC%. Attempt %COUNT% of 5. | |
PING %PC% -n 1 -w 100 > NUL | |
IF "%ERRORLEVEL%" EQU "0" ( | |
ECHO Connected. | |
:NOPING | |
CALL :PRINTBAR | |
ECHO Attempting to display user sessions... | |
ECHO. | |
QWINSTA /SERVER:%PC% | |
ECHO. | |
SET /P SESSIONID="Enter Session ID: " | |
MSTSC /v:%PC% /control /shadow:!SESSIONID! | |
GOTO END | |
) ELSE ( | |
ECHO %PC% failed to respond, trying again in 5 seconds... | |
TIMEOUT /T 5 /NOBREAK > NUL | |
GOTO PING | |
) | |
:FAILED_NOECHO | |
CALL :PRINTBAR | |
ECHO Failed to connect to the remote computer: [ %PC% ]. | |
ECHO The remote computer is not responding to ping requests. | |
GOTO END | |
:FAILED_NOHOST | |
CALL :PRINTBAR | |
ECHO Failed to connect to the remote computer: [ %PC% ]. | |
ECHO Unable to find the host's DNS entry. Does it exist? | |
GOTO END | |
:END | |
CALL :PRINTBAR | |
PAUSE | |
GOTO ENTRY | |
:PRINTBAR | |
ECHO ================================================================================ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment