Integrate RDP remote connection script

3 posts

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.

Reply
Shown with your post. Sign in to keep the same name every time.
(optional, never shown)
Only needed if you want notifications about replies.
Drag files here, paste a screenshot, or . Images up to 10 MB. Text, log and zip files up to 2 MB. Up to 5 files per post.
You can edit your post until someone replies.