Grabbing the output of Windows Message Box to a String

I have searched the webs for a solution to my problem with no avail. I need to assign the message box output of a specific command to a variable. The command is mstsc.exe /l. For a background this command lists the IDs of the screens available for a RDP session to a windows message box. I would like to capture this output to a string of sorts so that I can parse it to grab the IDs of the displays.

The mstsc /l output should look something like this and be assigned to a variable:

0:1920 x 1080; (0,0, xxxx, yyyy),

1:1920 x 1080; (0,0, xxxx, yyyy),

2:1920 x 1080; (0,0, xxxx, yyyy)

Any help would be very much appreciated.


Solution 1:

Not sure if there is a way to directly capture mstsc -l box but you could alternatively use powershell with a little research to leverage the required values programatically directly from .net

Add-Type -AssemblyName System.Windows.Forms
$Array = ([System.Windows.Forms.Screen]::AllScreens|sort -Property {$_.Displayname} )

$Array[0].Bounds.Width
$Array[0].Bounds.Height
$Array[0].Bounds.Left
$Array[0].Bounds.Top
($Array[0].Bounds.Right)-1
($Array[0].Bounds.Bottom)-1

$Array[1].Bounds.Width
$Array[1].Bounds.Height
$Array[1].Bounds.Left
$Array[1].Bounds.Top
($Array[1].Bounds.Right)-1
($Array[1].Bounds.Bottom)-1

$Array[2].Bounds.Width
$Array[2].Bounds.Height
$Array[2].Bounds.Left
$Array[2].Bounds.Top
($Array[2].Bounds.Right)-1
($Array[2].Bounds.Bottom)-1