I use RDP on many different windows machines, and sometimes have to RDP into one, then rdp from there onto another.
I'd like to know if it is possible to create a Batch File that can read the Names of all Directories within a set path, then display them as numbered variables like a menu. After i input my selection, it would do the same for all .rdp files in the selected directory.
Below is an example of how i could manually hardcode it for each file...but I need something that will adapt to dropping an new rdp file into a directory rather than having to manually add it each time inside the batch file, as the number of sites/pcs and names can change regularly.
:site
ECHO Location List
ECHO.
ECHO 1 NSW
ECHO 2 QLD
ECHO.
SET /p site=Enter Selection:
IF "%site%"=="1" GOTO NSW
IF "%site%"=="2" GOTO QLD
:NSW
SET dirname=C:\Machine\NSW\
ECHO Machine List
ECHO.
ECHO 1 Client01.rdp
ECHO 2 Server01.rdp
ECHO 3 Server02.rdp
ECHO.
SET /p machine0=Enter Selection:
IF "%machine0%"=="1" SET machine1=%dirname%Client01.rdp
IF "%machine0%"=="2" SET machine1=%dirname%Server01.rdp
IF "%machine0%"=="3" SET machine1=%dirname%Server02.rdp
GOTO connection
:connection
mstsc %machine1% /console
I've found several questions similar to this (such as here and here) but they all seem to be about just displaying a list and not getting them into a menu like option, also i still do not fully understand how the FOR command works.
Example of the directory structure.
C:\Batchfile.bat
C:\Machines\NSW\Client01.rdp
C:\Machines\NSW\Server01.rdp
C:\Machines\NSW\Server02.rdp
C:\Machines\QLD\Client01.rdp
C:\Machines\QLD\Client02.rdp
C:\Machines\QLD\Server01.rdp
The base directory would be set to C:\Machines then batch would store each sub-directory name to a numbered variable and echo them to the screen and prompt for selection.
Location List
1 NSW
2 QLD
Enter Selection:_
If user input 1 then then it would store each .RDP filename inside the QLD sub-directory to a numbered variable and echo them to the screen and prompt for selection.
Machine List for NSW
1 Client01.rdp
2 Server01.rdp
3 Server02.rdp
Enter Selection:_
After the user makes a selection at this point i would like to use the selected .rdp file with the mstsc command to launch an rdp session to the selected computer then loop back the beginning to allow to open a second connection at the same time.
I'd appreciate any help you could give.