Advertisement
Guest User

Untitled

a guest
Jun 5th, 2018
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using MSTSCLib;
  9.  
  10. namespace SampleRDC
  11. {
  12. public partial class Form1 : Form
  13. {
  14. public Form1()
  15. {
  16. InitializeComponent();
  17. }
  18.  
  19. private void button1_Click(object sender, EventArgs e)
  20. {
  21. try
  22. {
  23. rdp.Server = txtServer.Text;
  24. rdp.UserName = txtUserName.Text;
  25. IMsTscNonScriptable secured = (IMsTscNonScriptable)rdp.GetOcx();
  26. secured.ClearTextPassword = txtPassword.Text;
  27. rdp.Connect();
  28. }
  29. catch (Exception Ex)
  30. {
  31. MessageBox.Show("Error connecting to remote desktop " + txtServer.Text + " Error: " + Ex.Message,"Error Connecting",MessageBoxButtons.OK, MessageBoxIcon.Error);
  32. }
  33. }
  34.  
  35. private void button2_Click(object sender, EventArgs e)
  36. {
  37. try
  38. {
  39. if (rdp.Connected.ToString() == "1")
  40. rdp.Disconnect();
  41. }
  42. catch (Exception Ex)
  43. {
  44. MessageBox.Show("Error Disconnecting", "Error disconnecting from remote desktop " + txtServer.Text + " Error: " + Ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
  45. }
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement