How to programmatically log on to the terminal server session from Visual Basic

Source: Internet
Author: User
Summary

The Terminal Services ActiveX client control is not made public.ImstscnonscriptableInterface. However, you can use this interface to configure automatic logon for the terminal service session through programming. This allows the programmer to directly log on to the terminal service session without the "Windows login" Prompt window. The "details" section shows how to implement this function.
More information

To run this program, configure the terminal server as follows:

1. Log on to the terminal server as an administrator.
2. InStartClickProgram, ClickManagement toolsAnd then clickTerminal service configuration.
3. ClickConnection.
4. In the right pane, right-clickRDP-TCPAnd then selectAttribute.
5. ClickLogon SettingsTab.
6. DeselectAlways Prompt PasswordAnd then clickOK.

Remarks: For security reasons, Microsoft recommends that you do not implement this solution easily without careful or clear understanding of the Microsoft Windows security mechanism.
Sample Code


1. Start a new standard EXE project. By default, form1 is created.
2. InEngineeringOn the menu, click to selectComponents, SelectMicrosoft Terminal Services Control (redist)And then clickOK. If the control is unavailable, see the "Reference" section in this article to learn about how to download and install the control.
3. Add a Terminal Services Control on form1. Make sure it is large enough to display the session window.
4. Add threeLabelControls, threeTextboxControls, andCommandbuttonControl. Make sure that lable1 and text1 are on the same line, label2, text2, label3, and text3 are on the same line.
5. Paste the following code into the general declaration 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 okoption explicitprivate OBJ as imstscnonscriptableprivate sub form_load ()
Text1.text = ""
Text2.text = ""
Text3.text = ""
Label1.caption = "server"
Label2.caption = "username"
Label3.caption = "password"
Command1.caption = "Connect"
Text3.passwordchar = "*"
End subprivate sub commandementclick ()
Set OBJ = mstscax1.object
Mstscax1.server = text1.text
Mstscax1.username = text2.text
OBJ. cleartextpassword = text3.text
Mstscax1.connect
End sub

6. Save the project and press F5 to run the program. Note that after you enter the user name, password, and server name, no logon screen is displayed, prompting you to log on to the server. Microsoft recommends that you expand the terminal service. ocx file so that you can operateCloseDialog box.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.