Run Remote Desktop Connection after connecting PuTTY

I currently use some VBScript to:

- launch PuTTY;
- load a stored session; and
- connect to a LINUX firewall.

Once the connection has been established after manually entering the password, I then launch a RDP (Remote Desktop Connection) which has been configured to use the Tunnel and Port specified in PuTTY, and after all of this, I am finally connected to the computer I'm trying to reach.

Here's my question:  Is there some way that I can modify the following VBScript so that once the user has entered a correct password, I would like the specified Remote Desktop Connection to automatically launch?  I want to reduce my current 2-step login process to 1-step so that I only have to enter the password once when connecting to the LINUX box, and I don't have to manually then launch RDP.  I want that second step to happen automatically.

Any help would be greatly appreciated.
Option Explicit
Dim objShell
Set objShell = CreateObject("WScript.Shell")
objShell.run ("C:\Tunnel.exe")
Do Until objShell.AppActivate("PuTTY Configuration")                               
Loop
objShell.SendKeys "{Tab}{Tab}{Tab}{Tab}" 
objShell.SendKeys "{PgDn}{PgDn}" 
objShell.SendKeys "{Enter}" 
'-----> What can I put here to launch RDP after a successful connection to the LINUX box?

Open in new window

DanielAttardAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
DrDamnitConnect With a Mentor Commented:
If you want to automatically have the password put in, you'll need to follow the steps in this article to run CryptProtectData to calculate the password. Then write that to an rdp file, then use objShell.run("mstsc " & [filename.rdp] & " /console"
0
 
DrDamnitCommented:
objShell.Run ("mstsc /v: " & strMachineIP & "  /console")
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
DrDamnitCommented:
0
 
DrDamnitCommented:
How to script the terminal services client:
http://msdn2.microsoft.com/en-us/library/ms811527.aspx
0
 
DanielAttardAuthor Commented:
Thanks for the help.  Before attempting to get this working and automatically enter the password, first I will try to simply get RDP to launch.  I'll give your first suggestion a try and post back in a minute . . .
0
 
DrDamnitCommented:
You may also need this hot fix to generate RDP profiles directly from mstsc with the password saved in them: http://support.microsoft.com/kb/839918
0
 
DanielAttardAuthor Commented:
OK, you're first suggestion seemed to launch the RDP immediately upon connecting to the LINUX box.  I need to wait until the user enters the password before launching RDP.

Option Explicit
Dim objShell
Set objShell = CreateObject("WScript.Shell")
objShell.run ("C:\Tunnel.exe")
Do Until objShell.AppActivate("PuTTY Configuration")                              
Loop
objShell.SendKeys "{Tab}{Tab}{Tab}{Tab}"
objShell.SendKeys "{PgDn}{PgDn}"
objShell.SendKeys "{Enter}"
'-----> need to wait here until the password is entered
objShell.Run ("mstsc /v: 192.168.999.999 /console")

0
 
DanielAttardAuthor Commented:
Before I get into the more advanced topics, is there a way to hold-off on running RDP before the LINUX password is entered manually?
0
 
DanielAttardAuthor Commented:
I want to make sure we're on the same page.  When we talk about passwords, we're talking about the one to connect to the LINUX box, not the one required for RDP, correct?

I *want* the user to be required to enter the LINUX password; but after that the RDP should launch.
0
 
chandru_solCommented:
How they enter the password? Is that an inputbox?

regards
Chandru
0
 
DanielAttardAuthor Commented:
actually, i figured out how to enter the LINUX password automatically, now I just need to figure out how to launch a specified RDP file after the login with PuTTY.
0
 
chandru_solCommented:
I think Damnit has already given you on hoe to opn RDP file in the post ID: 20306009.

Did you try that?
0
 
DanielAttardAuthor Commented:
I did try that, but it didn't work.  This is the line that doesn't seem to be working:

objShell.Run ("mstsc /v: 192.168.2.151 /console")

What exactly does this command try to do?
0
 
chandru_solCommented:
That line is trying to connect to the IP address 192.168.2.151 and directly to console of that server

Do you get any error?
0
 
DanielAttardAuthor Commented:
What does:

/v:

refer to?

why the reference to V?

I am trying to launch RDP locally, not remotely.
0
 
DrDamnitCommented:
/v: tells rdp (mstsc) that this is the address you want to connect to.
0
 
chandru_solCommented:
try this command on your machine

mstsc /?

which will give you the answer for your question.

"I am trying to launch RDP locally, not remotely."
Are you trying to connect to any server or what you are trying to achieve?

regards
Chandru
0
 
DrDamnitCommented:
you said mstsc /v: 192.168.1.152 /console was not working...

Are you trying to connect to a microsoft remote desktop?
Is the firewall allowing connections on port 3389 (through all firewalls including the local machine as well as the linux firewalls on the inbetween).?
0
 
DanielAttardAuthor Commented:
Thanks for the replies again.
Yes, I am trying to connect to a microsoft remote desktop that is sitting behind the LINUX firewall.  The firewall does allow connections on port 3389.

What I am trying to do is tunnel through the LINUX box after the PuTTY connection is made.  I want to run RDP on my local machine.  I connect to localhost:10000 which is configured with the correct IP address and to use port 3389.
0
 
chandru_solCommented:
What box you are running this script from?

RDP to you local machine - why?
0
 
DanielAttardAuthor Commented:
I must have confused you.  I want to connect to my office computer from my laptop, which is where I am now.  I want to RDP to my office WIN XP machine, which sits behind a LINUX firewall, which is configured to allow connections on port 3389.
0
 
chandru_solCommented:
Is RDP enabled in your Windows XP machine?

Only one connection of RDP is allowed in Windows XP and when you connect on to it will automatically lock itself?

regards
Chandru
0
 
DanielAttardAuthor Commented:
Yes, RDP is enabled on the XP machine.
0
 
chandru_solCommented:
Have you added your username to the access list for the RDP as only the domain admins and administrators will have the access by default?

When you are trying to connect to your windows XP machine do you get any error?
0
 
DanielAttardAuthor Commented:
We are very close to solving this problem for me.  This code is working when I run it separately:

Set objShell = CreateObject("WScript.Shell")
objShell.Run "mstsc /v: localhost:10001 /console"

But when I include these lines at the end of this code:

Option Explicit
Dim objShell
Set objShell = CreateObject("WScript.Shell")
objShell.Run "C:\Tunnel.exe -load OPTC -pw ~OPTC-Admin#1"
Do Until objShell.AppActivate("PuTTY Configuration")                              
Loop
objShell.Run "mstsc /v: localhost:10001 /console" ' ___Not working

Why won't this last line run when it is part of the earlier code?
0
 
chandru_solCommented:
Becoz of the Do Loop as the code is still looping with in that loop

Try adding the code before the loop line

regards
Chandru
0
 
DanielAttardAuthor Commented:
You got it!  That was exactly the problem.  The Do Loop was causing the focus to remain with PuTTY which for some reason seemed to prevent the MSTSC line from running.  Now it seems to be connecting fine now that I have taken out the Do Loop which wasn't needed.
0
 
chandru_solCommented:
That's great!

Hope everything is working now

regards
Chandru
0
 
chandru_solConnect With a Mentor Commented:
I would also recommend you using this

strCommand = """C:\Tunnel.exe"" -load OPTC -pw ~OPTC-Admin#1"
objShell.Run strCommand, 1, True

which will make the other line run once it is completed

regards
Chandru
0
 
DanielAttardAuthor Commented:
Thanks for the help Chandru and DrDamnit.  I really appreciate you both helping me.
0
 
chandru_solCommented:
No worries! Cheers
0
 
chandru_solCommented:
Can you accept the solution?


regards
Chandru
0
All Courses

From novice to tech pro — start learning today.