Solved

Run Remote Desktop Connection after connecting PuTTY

Posted on 2007-11-17
33
2,466 Views
Last Modified: 2008-02-01
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

0
Comment
Question by:DanielAttard
  • 13
  • 12
  • 8
33 Comments
 
LVL 32

Expert Comment

by:DrDamnit
ID: 20305999
objShell.Run ("mstsc /v: " & strMachineIP & "  /console")
0
 
LVL 32

Accepted Solution

by:
DrDamnit earned 250 total points
ID: 20306009
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
 
LVL 32

Expert Comment

by:DrDamnit
ID: 20306011
0
 
LVL 32

Expert Comment

by:DrDamnit
ID: 20306020
0
 
LVL 32

Expert Comment

by:DrDamnit
ID: 20306022
How to script the terminal services client:
http://msdn2.microsoft.com/en-us/library/ms811527.aspx
0
 

Author Comment

by:DanielAttard
ID: 20306024
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
 
LVL 32

Expert Comment

by:DrDamnit
ID: 20306030
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
 

Author Comment

by:DanielAttard
ID: 20306034
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
 

Author Comment

by:DanielAttard
ID: 20306066
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
 

Author Comment

by:DanielAttard
ID: 20306079
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
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20306234
How they enter the password? Is that an inputbox?

regards
Chandru
0
 

Author Comment

by:DanielAttard
ID: 20306242
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
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20306245
I think Damnit has already given you on hoe to opn RDP file in the post ID: 20306009.

Did you try that?
0
 

Author Comment

by:DanielAttard
ID: 20306280
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
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20306305
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
 

Author Comment

by:DanielAttard
ID: 20306330
What does:

/v:

refer to?

why the reference to V?

I am trying to launch RDP locally, not remotely.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 32

Expert Comment

by:DrDamnit
ID: 20306352
/v: tells rdp (mstsc) that this is the address you want to connect to.
0
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20306357
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
 
LVL 32

Expert Comment

by:DrDamnit
ID: 20306358
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
 

Author Comment

by:DanielAttard
ID: 20306371
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
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20306382
What box you are running this script from?

RDP to you local machine - why?
0
 

Author Comment

by:DanielAttard
ID: 20306388
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
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20306399
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
 

Author Comment

by:DanielAttard
ID: 20306403
Yes, RDP is enabled on the XP machine.
0
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20306411
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
 

Author Comment

by:DanielAttard
ID: 20306445
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
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20306449
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
 

Author Comment

by:DanielAttard
ID: 20306480
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
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20306496
That's great!

Hope everything is working now

regards
Chandru
0
 
LVL 12

Assisted Solution

by:chandru_sol
chandru_sol earned 250 total points
ID: 20306503
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
 

Author Comment

by:DanielAttard
ID: 20306513
Thanks for the help Chandru and DrDamnit.  I really appreciate you both helping me.
0
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20306521
No worries! Cheers
0
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20381850
Can you accept the solution?


regards
Chandru
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now