C#实现计算机远程操作

C#实现计算机远程操作

1、windows远程桌面连接
在 Visual Studio 中添加引用,添加 COM 中的 “Microsoft Terminal Services Control Type Library”,这个过程将会把 MSTSCLib.dll 添加到项目中。
在这里插入图片描述

在这里插入图片描述

在工具栏中添加控件,在工具栏上右键选择“选择项…”,将 COM 组件中的 “Microsoft Terminal Services Client Control” 选中,确定后就会有相应的控件出现,然后拖拽就可以使用了。
在这里插入图片描述

代码的实现
axMsTscAxNotSafeForScripting1 为控件的名称,str_computer 为 IP 地址、str_userName 为用户名、str_password 为密码。
using MSTSCLib;

this.axMsRdpClient71.Server = “192.168.4.188”;
this.axMsRdpClient71.UserName = “Administrator”;
IMsTscNonScriptable secured = (IMsTscNonScriptable)this.axMsRdpClient71.GetOcx();
secured.ClearTextPassword = “123456654321”;
this.axMsRdpClient71.Connect();

2、对于类Linux远程操作

使用到包:SharpSSH-1.1.1.13.bin
引用Tamir.SharpSsh

核心代码:
public static string RunSSHCommands(String host, String username, String password, String[] commands)
{
string output = null;
if (commands == null || commands.Length == 0)
return null;
try
{
SshExec exec = new SshExec(host, username);
exec.Password = password;
exec.Connect();
foreach (String command in commands)
{
if (command == null || command.Trim().Length == 0) continue;
output += exec.RunCommand(command);
}
exec.Close();
return output;
}
catch (Exception e)
{
output = e.Message;
return output;
}
}
登录服务器执行:
string[] comstr = new string[1];
comstr[0] = this.textBox1.Text;
this.label1.Text = RunSSHCommands(“192.168.32.243”, “root”, “你机器的密码”, comstr);

程序的源程序下载:源码与资源下载

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

刘二光

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值