Search code examples
batch-filewindows-10putty

putty connection and remote desktop connection together in one batch script


I need to connect remotely in another network with putty and then start a windows remote desktop connection. these are 2 steps with 2 sets of passwords, I want to just have one batch script to run once for both steps.

I did the single commands:

pathPuttyexe -load "myconnection" -pw password

to connect from windows 10 with putty, then

mstsc myfileconfig.rdp 

to run the remote desktop connection application with my configuration.

The problem I have is if I put the 2 commands in one bat file, it executes the second only after the first is finished. That means while the connection to the other network is live, the Remote Desktop Connection app doesn't run. The & didn't work; with while do I couldn't make it work...


Solution

  • To start them in sync as a one liner:

    pathPuttyexe -load "myconnection" -pw password | mstsc myfileconfig.rdp
    

    Or using start:

    start "" mstsc myfileconfig.rdp
    start "" pathPuttyexe -load "myconnection" -pw password
    

    If you want to run it in sequence, in other words the one starts after the other and on at the same time:

    pathPuttyexe -load "myconnection" -pw password & mstsc myfileconfig.rdp
    

    or with conditional operator && meaning the second process will only start IF the first started successful.

    pathPuttyexe -load "myconnection" -pw password && mstsc myfileconfig.rdp
    

    or just straight forward line seperated:

    mstsc myfileconfig.rdp
    pathPuttyexe -load "myconnection" -pw password