Microsoft KB Archive/281417

= How To Log On to a Terminal Server Session Programmatically from Visual Basic =

Article ID: 281417

Article Last Modified on 2/28/2006

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft IntelliMouse Web 1.0

-



This article was previously published under Q281417



SUMMARY
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 &quot;More Information&quot; section.



MORE INFORMATION
To run this program, configure your Terminal Server computer as follows:
 * 1) Log on to the Terminal Server locally as an administrator.
 * 2) On the Start button, click Programs, click Administrative Tools, and then click Terminal Services Configuration.
 * 3) Click on Connections.
 * 4) In the right pane, right-click RDP-Tcp, and then choose Properties.
 * 5) Click on the Logon Settings tab.
 * 6) 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.

Sample Code
 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 &quot;References&quot; 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 &quot;Logon Settings&quot; Tab ' Uncheck &quot;Always prompt for password&quot; and click OK

Option Explicit

Private Obj As IMsTscNonScriptable

Private Sub Form_Load Text1.Text = &quot;&quot; Text2.Text = &quot;&quot; Text3.Text = &quot;&quot; Label1.Caption = &quot;Server&quot; Label2.Caption = &quot;UserName&quot; Label3.Caption = &quot;Password&quot; Command1.Caption = &quot;Connect&quot; Text3.PasswordChar = &quot;*&quot; 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.</ol>

<div class="references_section">