Integrate RDP remote connection script

3 posts · Closed

Antony Guest
4 Nov 2025

Hi,
I have a script that I use to initiate a remote connection via RDP to the client. I would like to integrate this script into Network Scanner.

set /p target=Hostname
for /f "tokens=3" %%a in ('qwinsta /server:%target% ^| findstr /i console') do mstsc /v:%target% /shadow: %%a /control

Thank you in advance.

Andrew SoftPerfect
6 Nov 2025

For that you'd need to create a batch file like this:

@echo off
setlocal

if "%~1"=="" goto :usage
set "target=%~1"

rem grab the console session id and shadow it
for /f "tokens=3" %%a in ('qwinsta /server:%target% ^| findstr /i "console"') do (
  mstsc /v:%target% /shadow:%%a /control
  goto :eof
)

echo No console session found on %target%.
exit /b 2

:usage
echo Error: No hostname specified.
echo Usage: %~nx0 HOSTNAME
exit /b 1

Name it shadow.bat. Then add it to Applications within the Network Scanner app as:

cmd.exe /k C:\path\to\shadow.bat %0

This it will appear in the list of applications and you can launch it against any selected device.

Antony Guest
13 Nov 2025

Everything worked out wonderfully.
Thank you very much again.

This topic is closed. It has had no new posts for over a year, so the software versions it talks about may be out of date. Start a new topic in Network Scanner if you have a similar question.