The Terminal Services ActiveX client control does not
expose the ImsTscNonScriptable interface. However, this interface can be used to configure
automatic log on for a Terminal Services Session programmatically, which
enables the programmer to log a user on to a Terminal Services Session without
receiving the Windows Logon prompt. This is demonstrated in the sample in the
"More Information" section.
To run this program, configure your Terminal Server
computer as follows:
Log on to the Terminal Server locally as an
administrator.
On the Start button, click Programs, click Administrative Tools, and then click Terminal Services Configuration.
Click on Connections.
In the right pane, right-click RDP-Tcp, and then choose Properties.
Click on the Logon Settings tab.
Deselect Always prompt for password, and then click OK.
NOTE: For security reasons, Microsoft recommends that you do not
implement this scenario without extreme care and a clear understanding of
Microsoft Windows security.
Start a new Standard EXE project. Form1 is created by
default.
On the Project menu, click to select Components, select Microsoft Terminal Services Control(redist), and then click OK. If this control is not available, see the "References" section
of this article for information on how to download and install it.
Add one Terminal Services Control to Form1, making sure it
is big enough to handle the display of the session.
Add three Label controls, three TextBox controls, and one CommandButton control to Form1. Make sure that Lable1 and Text1 are on the same
line, and that Label2, Text2, Label3, and Text3 are on the same
line.
Paste the following code into the General Declarations of
Form1:
' This code only works when you set the configuration on the Server-side.
' Log on to the Terminal Server as an administrator
' Start\Programs\Administrative Tools\Terminal Services Configuration
' Click on Connections
' On the Right Pane, right-click on RDP-Tcp and choose Properties
' Click on the "Logon Settings" Tab
' Uncheck "Always prompt for password" and click OK
Option Explicit
Private Obj As IMsTscNonScriptable
Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Label1.Caption = "Server"
Label2.Caption = "UserName"
Label3.Caption = "Password"
Command1.Caption = "Connect"
Text3.PasswordChar = "*"
End Sub
Private Sub Command1_Click()
Set Obj = MsTscAx1.Object
MsTscAx1.Server = Text1.Text
MsTscAx1.UserName = Text2.Text
Obj.ClearTextPassword = Text3.Text
MsTscAx1.Connect
End Sub
Save the project, press the F5 key to run it, and note that
after you supply your username, password, and server name, you are not prompted
for a logon screen at the server. Microsoft recommends that you enlarge the
Terminal Server .ocx file so that you are able to manipulate the Shut Down dialog box.