Is it Possible to use a HTA file and call Remote Desktop?

Hi all

I have looked on the internet for a solution but I have come up empty. I want to use a HTA script to call remote desktop. Also I want this script to collect the machine name or IP and Username and Password so it would auto log you in. I have a very small script that will call the RPD but that is it. Is there any commands that will collect the username password and IP address?
OTNAdminAsked:
Who is Participating?
 
RobSampsonConnect With a Mentor Commented:
Hi, there is no way to pass the password to a Remote Desktop session, unless you use the GUI to save that password to an RDP file.
Run MSTSC, expand the Options, type in the Password, tick Save my password, and click the Save As button.  This will save an RDP file with the password in there as a byte string.  Then you can run:

Set objShell = CreateObject("WScript.Shell")
strRDPPath = "C:\Temp\Connect.RDP"
objShell.Run "MSTSC " & strRDPPath, 1, True

But, you can't ask the user for the password and then write this to an RDP file. You can, however, write a base RDP file, with content like:

screen mode id:i:2
desktopwidth:i:1280
desktopheight:i:1024
session bpp:i:16
winposstr:s:0,1,0,0,1024,738
full address:s:YOURSERVERNAME
compression:i:1
keyboardhook:i:2
audiomode:i:0
redirectdrives:i:0
redirectprinters:i:1
redirectcomports:i:0
redirectsmartcards:i:1
displayconnectionbar:i:1
autoreconnection enabled:i:1
username:s:YOURUSERNAME
domain:s:YOURDOMAINNAME
alternate shell:s:
shell working directory:s:
disable wallpaper:i:1
disable full window drag:i:1
disable menu anims:i:1
disable themes:i:0
disable cursor setting:i:0
bitmapcachepersistenable:i:1


and then run *that* RDP file, and it will prompt for the password anyway.

To write *that* to a file, use a VBS like:

'========================
strRDPPath = "C:\Temp\Connect.RDP"
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

strServer = InputBox("Please enter your server name:", "Server")
strUserName = InputBox("Please enter your user name:", "Username")
strDomainName = InputBox("Please enter your domain name:", "Domain Name")

strContent = _
      "screen mode id:i:2" & VbCrLf & _
      "desktopwidth:i:1280" & VbCrLf & _
      "desktopheight:i:1024" & VbCrLf & _
      "session bpp:i:16" & VbCrLf & _
      "winposstr:s:0,1,0,0,1024,738" & VbCrLf & _
      "full address:s:" & strServer & VbCrLf & _
      "compression:i:1" & VbCrLf & _
      "keyboardhook:i:2" & VbCrLf & _
      "audiomode:i:0" & VbCrLf & _
      "redirectdrives:i:0" & VbCrLf & _
      "redirectprinters:i:1" & VbCrLf & _
      "redirectcomports:i:0" & VbCrLf & _
      "redirectsmartcards:i:1" & VbCrLf & _
      "displayconnectionbar:i:1" & VbCrLf & _
      "autoreconnection enabled:i:1" & VbCrLf & _
      "username:s:" & strUsername & VbCrLf & _
      "domain:s:" & strDomainName & VbCrLf & _
      "alternate shell:s:" & VbCrLf & _
      "shell working directory:s:" & VbCrLf & _
      "disable wallpaper:i:1" & VbCrLf & _
      "disable full window drag:i:1" & VbCrLf & _
      "disable menu anims:i:1" & VbCrLf & _
      "disable themes:i:0" & VbCrLf & _
      "disable cursor setting:i:0" & VbCrLf & _
      "bitmapcachepersistenable:i:1"

Set objRDPFile = objFSO.CreateTextFile(strRDPPath, True)
objRDPFile.Write strContent
objRDPFile.Close
Set objRDPFile = Nothing

strRDPPath = objFSO.GetFile(strRDPPath).ShortPath
objShell.Run "MSTSC " & strRDPPath, 1, True

objFSO.DeleteFile strRDPPath, True
'========================

which could easily be converted to a Sub for a HTA.

Regards,

Rob.
0
 
OTNAdminAuthor Commented:
Great work
0
All Courses

From novice to tech pro — start learning today.