Search code examples
batch-fileremote-desktoprdpmstsc

Batch Multiple Active Remote desktop sessions


I want to see if mutliple active remote desktop sessions are running on my client PC using a batch script.

When I open my Task Manager I can see a (2) behind MSTSC.exe

I already used:

wmic process where name="mstsc.exe" | find "mstsc.exe" /c

But the result I get is 1 even if there are two remote desktop sessions active.

I wonder if anyone can help me with this challenge.


Solution

  • Why not use a simpler method:

    TaskList|Find /I /C "mstsc.exe"
    

    To save the number as a variable in a batch file:

    @For /F %%A In ('TaskList^|Find /I /C "mstsc.exe"') Do @Set "Num=%%A"
    @Echo %Num%
    

    If you still wished to use WMIC for the task then perhaps you could change your provided example to:

    WMIC Process Where Name="mstsc.exe" Get Name | Find /I /C "mstsc.exe"