11 Mart 2015 Çarşamba

C# ile Uzak Masaüstü Bağlantısı

Framework 4.0 ile Uzak Masaüstü bağlantısı yapmak bir iki satır kod ile; Bunun için sisteme önce Yeni bir proje oluşturarak References bölümünden Add Reference diyerek COM Componentsbölümüne geçiniz. Orada Micorosft Terminal Service Active Client 1.0 Type Libary referansını bulup projemize ekliyoruz.
Daha SonraToolbox da Buradan Microsoft Terminal Services Client Control Version-1 objesine projemize sürükleyip bırakıyoruz. Bu yapıyı oluşturduktan sonra projemize üç textbox, ve iki buton ekleyelim. Görüntü ve işlem adımları aşağıdaki gibi;
uzakmasaustucsharp1Kırmızı çerçevelere bakarak refarans ekliyoruz.
uzakmasaustucsharp2 sonra forma Toolboxa gelen nesneyi ekliyoruz.uzakmasaustucsharp3
Kullandığım form ve nesne isimleri yukarıdaki gibidir.
//refaranslarını eklemeyi unutmayın
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MSTSCLib;
//butonların olayları aşağıdaki gibi olacak;
private void button1_Click(object sender, EventArgs e)
{ try
{
axMsTscAxNotSafeForScripting1.Server = txtUzakIp.Text;
axMsTscAxNotSafeForScripting1.UserName = txtoturumAdi.Text;
IMsTscNonScriptable secured = (IMsTscNonScriptable)axMsTscAxNotSafeForScripting1.GetOcx();
secured.ClearTextPassword = txtSifre.Text;
axMsTscAxNotSafeForScripting1.Connect();
}
catch (Exception Ex)
{
MessageBox.Show(“Bağlantı Hatası”, “Pc’ye Ulaşılamadı. ” + lblhata.Text + ” Hata: ” + Ex.Message,MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void button2_Click(object sender, EventArgs e)
{
try
{
// Oturum açık ise sonlandır.
if (axMsTscAxNotSafeForScripting1.Connected.ToString() == “1”)
axMsTscAxNotSafeForScripting1.Disconnect();
}
catch (Exception Ex)
{
MessageBox.Show(“Bağlantı Hatası”, “Pc’ye Ulaşılamadı. ” + lblhata.Text + ” Hata: ” + Ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

Hiç yorum yok :

Yorum Gönder