Hide cloudflared.exe output?

I use a .bat to make it easier for my users to connect to RDP through a tunnel:

echo @off
set /a portlocal=%random% %%32767 +20000
start /min cmd /c "C:\Program Files (x86)\cloudflared\cloudflared.exe" access rdp --hostname foo.foo.com --url localhost:%portlocal% > a.txt 2>&1
start mstsc.exe -v localhost:%portlocal%

Is there any way to hide the output of cloudflared.exe in access mode?

image

It is very annoying for users to see a shell with things they don’t understand.

Sounds like you want to add --loglevel error (or even “fatal”) to your cloudflared access command.

With --loglevel error no messages are displayed, but the user still sees a black window (shell) that fails if closed.

So you want to start a command without having the shell at all. Basically starting it in the background?

An equivalent to

command &

on linux?

If so, please try to start it like this:

start /B ""

In your case should look something like this:

start /B "Cloudflare" cmd /c "C:\Program Files (x86)\cloudflared\cloudflared.exe" access rdp --hostname foo.foo.com --url localhost:%portlocal% > a.txt 2>&1

This should start a new CMD process in the background without any new CMD/Shell window which is named “Cloudflare”, so you will still be able to find it in the taskmanager.

For more info, please run:

HELP START

which shows you all possible parameters etc.

Another option is to install Windows own SSH Server (musst be installed seperately) and run the command through it, like this:

ssh username@localhost "command to start"

This will also survive the closing of the parent CMD/Shell

This is untested tho

Yes, like linux does with command &

I have tried

 start /B "Cloudflare" cmd /c "C:\Program Files (x86)\cloudflared\cloudflared.exe" access rdp --hostname foo.foo.com --url localhost:59315 --loglevel fatal

but it does not work as in Linux, the process remains in background as long as the CMD window is not closed.

If you launch it in a shortcut, cloudflared.exe opens and closes immediately, giving localhost:59315 as unreachable.

Ideally, cloudflared.exe would support that option with a service, or have an agent like WARP in the task bar.

That is a pitty.
I just see two options as for now.

  1. SSH Server
  2. maybe give Hidden Start/hstart a try

You can open that feature request.

Thanks, I will try hidden start, I didn’t know it.

Yes, I will do it.

I had the same question today and this thread popped up. I’ve gotten closer with some trial an error.

If you want the user to control (and exit) cloudflared, I would think the OP’s original batch file is pretty close. The /min parameter should run cloudflared in a fairly unobtrusive, minimized command window. They can close cloudflared by closing the window.

This post lists several other alternatives to running batch files silently:

The scheduled task idea doesn’t work because to be fully hidden it has to run in a different user process, which means it won’t be able to launch the browser prompt for authentication.

Gemini AI has a couple more ideas:

Powershell

Start-Process -WindowStyle Hidden -FilePath "C:\Program Files (x86)\cloudflared\cloudflared.exe" -ArgumentList "access rdp --hostname foo.foo.com --url rdp://localhost:3390"

Save that as cloudflared.ps1 then run from a batch file like this:

start /min powershell.exe -NoLogo -NoProfile -NonInteractive -Command C:\bat\cloudflared.ps1; exit $LASTEXITCODE

That gives only a brief command window flash before disappearing. Not bad.

VBScript - haven’t tried - create the script run_hidden.vbs:

Set objShell = CreateObject("WScript.Shell")
objShell.Run """path\to\your\executable.exe""", 0, False

then execute from a command file:

cscript.exe "path\to\run_hidden.vbs"

Supposedly this approach has no command window flash.

How to stop it?

What if cloudflared is running hidden and the user needs to restart the RDP session? They click on the command file and another instance of cloudflared starts, on a different port… They could find cloudflared in Task Manager to end the task, or you could write another script to kill cloudflared (maybe use pskill). Maybe the simplest thing would be to use a static port, set up Remote Desktop to use that port, then just let cloudflared run until the user logs off (it’s pretty small: 150 handles / 13MB).

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.