Batch file to connect to Cloudflare RDP Access

Batch file to connect to Cloudflare RDP Access

Scenario:

You want to connect to remote desktop which is configured through cloudflare. Everytime you need to open the cloudfled exe file and then connect through mstsc.

I have created a batch file which will connect directly to the pc. It will also download the cloudflred.exe from server if not exist in windows pc. I also added commands to unizp and extract the file.

Note that this works and tested in Windows 10.

@ECHO off
cls

if not exist "%USERPROFILE%\cloudflare\cloudflared.exe" (
	ECHO.
	ECHO ###################################
	ECHO Cannot find cloudflare software. We are downloading and installing which will take upto 5 minutes.
	ECHO One Time Process. Please drink your coffee and wait.
	ECHO ###################################
	if not exist "%USERPROFILE%\cloudflare\"  mkdir "%USERPROFILE%\cloudflare"
    curl https://bin.equinox.io/c/VdrWdbjqyF/cloudflared-stable-windows-amd64.zip --output %USERPROFILE%\cloudflare\cloudflared.zip --silent
	Call :UnZipFile "%USERPROFILE%\cloudflare\" "%USERPROFILE%\cloudflare\cloudflared.zip"    
)
goto start
:start
ECHO.
ECHO ###################################
ECHO Cloudflare  Connector Utility
ECHO ###################################
ECHO.
ECHO.
start %USERPROFILE%\cloudflare\cloudflared.exe access rdp --hostname xyz.haneefputtur.com --url localhost:2241
start MSTSC /v:localhost:2241
pause
exit
:UnZipFile <ExtractTo> <newzipfile>
set vbs="%temp%\_.vbs"
if exist %vbs% del /f /q %vbs%
>%vbs%  echo Set fso = CreateObject("Scripting.FileSystemObject")
>>%vbs% echo If NOT fso.FolderExists(%1) Then
>>%vbs% echo fso.CreateFolder(%1)
>>%vbs% echo End If
>>%vbs% echo set objShell = CreateObject("Shell.Application")
>>%vbs% echo set FilesInZip=objShell.NameSpace(%2).items
>>%vbs% echo objShell.NameSpace(%1).CopyHere(FilesInZip)
>>%vbs% echo Set fso = Nothing
>>%vbs% echo Set objShell = Nothing
cscript //nologo %vbs%
if exist %vbs% del /f /q %vbs%