CMD script integration

Started by Antony

Antony

CMD script integration   04 November 2025, 22:14

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.
SoftPerfect Support forum - Andrew avatar image

Re: CMD script integration   07 November 2025, 09:33

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

Re: CMD script integration   14 November 2025, 02:01

Everything worked out wonderfully.
Thank you very much again.

Reply to this topic

Sometimes you can find a solution faster if you try the forum search, have a look at the knowledge base, or check the software user manual to see if your question has already been answered.

Our forum rules are simple:

  • Be polite.
  • Do not spam.
  • Write in English. If possible, check your spelling and grammar.

Author:

Email:

Subject

A brief and informative title for your message, approximately 4–8 words:

     

Spam prevention: please enter the following code in the input field below.

 ********   ********  **     **  **     **  **     ** 
 **     **  **        **     **  **     **   **   **  
 **     **  **        **     **  **     **    ** **   
 ********   ******    *********  **     **     ***    
 **         **        **     **  **     **    ** **   
 **         **        **     **  **     **   **   **  
 **         ********  **     **   *******   **     ** 

Message: