• c#实现windows远程桌面连接程序代码


    使用winform制作windows远程桌面连接程序,windows自带了远程桌面连接,我们需要将远程桌面连接集成

    到自己的winform程序,并实现管理远程主机的配置。

    远程桌面核心类库

    windows系统自带了远程桌面activex dll,目录:

    c:WindowsSystem32mstscax.dll

    此类库无法使用c#直接调用,介绍一个工具AxImp.exe

    AxImp.exe

    https://msdn.microsoft.com/zh-cn/library/8ccdh774(VS.80).aspx

    ActiveX 控件导入程序将 ActiveX 控件的 COM 类型库中的类型定义转换为 Windows 窗体控件。

    控件转换

    在cmd输入以下命令

    "c:Program Files (x86)Microsoft SDKsWindowsv7.0ABinAxImp.exe" "c:WindowsSystem32mstscax.dll"

    即可生成AxMSTSCLib.dll,MSTSCLib.dll

    //远程连接核心方法
    private AxMSTSCLib.AxMsRdpClient7 rdpc = null;
    protected void OnCreateControl()
    {
      rdpc = new AxMSTSCLib.AxMsRdpClient7();
      rdpc.OnDisconnected += new AxMSTSCLib.IMsTscAxEvents_OnDisconnectedEventHandler(rdpc_OnDisconnected);
      this.Controls.Add(rdpc);
      rdpc.Dock = DockStyle.Fill;
      rdpc.BringToFront();
    }
     
    void rdpc_OnDisconnected(object sender, AxMSTSCLib.IMsTscAxEvents_OnDisconnectedEvent e)
    {
      //处理断开连接
    }
     
     
    public void Disconnect()
    {
      try
      {
        if (rdpc.Connected == 1)
        {
          rdpc.Disconnect();
        }
      }
      catch (Exception)
      {
     
      }
     
    }
     
    private void SetRdpClientProperties(Machine parMachine)
    {
      rdpc.Server = parMachine.MachineName;
      rdpc.AdvancedSettings2.RDPPort = parMachine.Port;
      rdpc.UserName = parMachine.UserName;
      rdpc.Domain = parMachine.DomainName;
      if (parMachine.Password != "")
      {
        rdpc.AdvancedSettings5.ClearTextPassword = parMachine.Password;
      }
      rdpc.AdvancedSettings5.RedirectDrives = parMachine.ShareDiskDrives;
      rdpc.AdvancedSettings5.RedirectPrinters = parMachine.SharePrinters;
      rdpc.ColorDepth = (int)parMachine.ColorDepth;
    }
     
    public void Connect(Machine parMachine)
    {
      SetRdpClientProperties(parMachine);
      rdpc.Connect();
    }
     
    //远程主机配置
    [Serializable()]
    public class Machine
    {
      private string _RemoteDesktopConnectionName;
      public string RemoteDesktopConnectionName
      {
        get { return _RemoteDesktopConnectionName; }
        set { _RemoteDesktopConnectionName = value; }
      }
     
      private string _MachineName;
      public string MachineName
      {
        get { return _MachineName; }
        set { _MachineName = value; }
      }
      private string _DomainName;
      public string DomainName
      {
        get { return _DomainName; }
        set { _DomainName = value; }
      }
     
      private string _UserName;
      public string UserName
      {
        get { return _UserName; }
        set { _UserName = value; }
      }
     
      private string _Password;
      public string Password
      {
        get { return _Password; }
        set { _Password = value; }
      }
     
      private bool _AutoConnect;
      public bool AutoConnect
      {
        get { return _AutoConnect; }
        set { _AutoConnect = value; }
      }
     
      private bool _ShareDiskDrives;
      public bool ShareDiskDrives
      {
        get { return _ShareDiskDrives; }
        set { _ShareDiskDrives = value; }
      }
     
      private bool _SharePrinters;
      public bool SharePrinters
      {
        get { return _SharePrinters; }
        set { _SharePrinters = value; }
      }
     
      private bool _SavePassword;
      public bool SavePassword
      {
        get { return _SavePassword; }
        set { _SavePassword = value; }
      }
     
      private Colors _ColorDepth;
      public Colors ColorDepth
      {
        get { return _ColorDepth; }
        set { _ColorDepth = value; }
      }
     
      public int Port
      {
        get
        {
          return _Port;
        }
     
        set
        {
          _Port = value;
        }
      }
     
      private int _Port;
     
     
      public enum Colors
      {
        HighColor15 = 15,
        HighColor16 = 16,
        Color256 = 8,
        TrueColor = 24
      }
    }

    以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

     
     

    原文链接:http://www.cnblogs.com/theLife/p/6838745.html

     

     

    使用winform制作windows远程桌面连接程序,windows自带了远程桌面连接,我们需要将远程桌面连接集成

    到自己的winform程序,并实现管理远程主机的配置。

    远程桌面核心类库

    windows系统自带了远程桌面activex dll,目录:

    c:WindowsSystem32mstscax.dll

    此类库无法使用c#直接调用,介绍一个工具AxImp.exe

    AxImp.exe

    https://msdn.microsoft.com/zh-cn/library/8ccdh774(VS.80).aspx

    ActiveX 控件导入程序将 ActiveX 控件的 COM 类型库中的类型定义转换为 Windows 窗体控件。

    控件转换

    在cmd输入以下命令

    "c:Program Files (x86)Microsoft SDKsWindowsv7.0ABinAxImp.exe" "c:WindowsSystem32mstscax.dll"

    即可生成AxMSTSCLib.dll,MSTSCLib.dll

    远程桌面连接核心代码

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    //远程连接核心方法
    private AxMSTSCLib.AxMsRdpClient7 rdpc = null;
    protected void OnCreateControl()
    {
      rdpc = new AxMSTSCLib.AxMsRdpClient7();
      rdpc.OnDisconnected += new AxMSTSCLib.IMsTscAxEvents_OnDisconnectedEventHandler(rdpc_OnDisconnected);
      this.Controls.Add(rdpc);
      rdpc.Dock = DockStyle.Fill;
      rdpc.BringToFront();
    }
     
    void rdpc_OnDisconnected(object sender, AxMSTSCLib.IMsTscAxEvents_OnDisconnectedEvent e)
    {
      //处理断开连接
    }
     
     
    public void Disconnect()
    {
      try
      {
        if (rdpc.Connected == 1)
        {
          rdpc.Disconnect();
        }
      }
      catch (Exception)
      {
     
      }
     
    }
     
    private void SetRdpClientProperties(Machine parMachine)
    {
      rdpc.Server = parMachine.MachineName;
      rdpc.AdvancedSettings2.RDPPort = parMachine.Port;
      rdpc.UserName = parMachine.UserName;
      rdpc.Domain = parMachine.DomainName;
      if (parMachine.Password != "")
      {
        rdpc.AdvancedSettings5.ClearTextPassword = parMachine.Password;
      }
      rdpc.AdvancedSettings5.RedirectDrives = parMachine.ShareDiskDrives;
      rdpc.AdvancedSettings5.RedirectPrinters = parMachine.SharePrinters;
      rdpc.ColorDepth = (int)parMachine.ColorDepth;
    }
     
    public void Connect(Machine parMachine)
    {
      SetRdpClientProperties(parMachine);
      rdpc.Connect();
    }
     
    //远程主机配置
    [Serializable()]
    public class Machine
    {
      private string _RemoteDesktopConnectionName;
      public string RemoteDesktopConnectionName
      {
        get { return _RemoteDesktopConnectionName; }
        set { _RemoteDesktopConnectionName = value; }
      }
     
      private string _MachineName;
      public string MachineName
      {
        get { return _MachineName; }
        set { _MachineName = value; }
      }
      private string _DomainName;
      public string DomainName
      {
        get { return _DomainName; }
        set { _DomainName = value; }
      }
     
      private string _UserName;
      public string UserName
      {
        get { return _UserName; }
        set { _UserName = value; }
      }
     
      private string _Password;
      public string Password
      {
        get { return _Password; }
        set { _Password = value; }
      }
     
      private bool _AutoConnect;
      public bool AutoConnect
      {
        get { return _AutoConnect; }
        set { _AutoConnect = value; }
      }
     
      private bool _ShareDiskDrives;
      public bool ShareDiskDrives
      {
        get { return _ShareDiskDrives; }
        set { _ShareDiskDrives = value; }
      }
     
      private bool _SharePrinters;
      public bool SharePrinters
      {
        get { return _SharePrinters; }
        set { _SharePrinters = value; }
      }
     
      private bool _SavePassword;
      public bool SavePassword
      {
        get { return _SavePassword; }
        set { _SavePassword = value; }
      }
     
      private Colors _ColorDepth;
      public Colors ColorDepth
      {
        get { return _ColorDepth; }
        set { _ColorDepth = value; }
      }
     
      public int Port
      {
        get
        {
          return _Port;
        }
     
        set
        {
          _Port = value;
        }
      }
     
      private int _Port;
     
     
      public enum Colors
      {
        HighColor15 = 15,
        HighColor16 = 16,
        Color256 = 8,
        TrueColor = 24
      }
    }

    以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

     
     

    原文链接:http://www.cnblogs.com/theLife/p/6838745.html

  • 相关阅读:
    一分钟应对勒索病毒WannaCry
    你不知道网络安全有多严峻
    MongoDB 文章目录
    SQL Server 文章目录
    MySQL 文章目录
    领域驱动(DD)目录
    Oracle基本教程
    系统架构研究目录
    设计原则目录
    开源项目学习历程
  • 原文地址:https://www.cnblogs.com/wangchuang/p/9413172.html
Copyright © 2020-2023  润新知