学生因大作业需求,向大佬们请教下c#连接rdp和remoteapp的方法,可以有偿
学生因大作业需求,向大佬们请教下c#连接rdp和remoteapp的方法,可以有偿{:5_96:}比如这个怎么利用c#程序实现链接这个rdp文件
allow desktop composition:i:1
allow font smoothing:i:1
alternate full address:s:119.91.206.185
alternate shell:s:rdpinit.exe
devicestoredirect:s:*
disableremoteappcapscheck:i:1
drivestoredirect:s:*
full address:s:119.91.206.185
prompt for credentials on client:i:1
promptcredentialonce:i:0
redirectcomports:i:1
redirectdrives:i:1
remoteapplicationmode:i:1
remoteapplicationname:s:AliWorkbench
remoteapplicationprogram:s:||AliWorkbench
span monitors:i:1
use multimon:i:1
q3455214945 本帖最后由 歌者文明清理员 于 2023-6-18 10:26 编辑
您好,连接 RDP 和 RemoteApp 的方法在 C# 中可以使用 System.Net.Sockets 命名空间中的 TcpClient 类实现。可以参考以下代码实现:
using System;
using System.Net.Sockets;
namespace ConnectRdpDemo
{
class Program
{
static void Main(string[] args)
{
string rdpFileContent = "allow desktop composition:i:1\n" +
"allow font smoothing:i:1\n" +
"alternate full address:s:119.91.206.185\n" +
"alternate shell:s:rdpinit.exe\n" +
"devicestoredirect:s:*\n" +
"disableremoteappcapscheck:i:1\n" +
"drivestoredirect:s:*\n" +
"full address:s:119.91.206.185\n" +
"prompt for credentials on client:i:1\n" +
"promptcredentialonce:i:0\n" +
"redirectcomports:i:1\n" +
"redirectdrives:i:1\n" +
"remoteapplicationmode:i:1\n" +
"remoteapplicationname:s:AliWorkbench\n" +
"remoteapplicationprogram:s:||AliWorkbench\n" +
"span monitors:i:1\n" +
"use multimon:i:1";
string[] rdpParameters = rdpFileContent.Split('\n');
TcpClient tcpClient = new TcpClient();
tcpClient.Connect("119.91.206.185", 3389);
NetworkStream networkStream = tcpClient.GetStream();
foreach (var parameter in rdpParameters)
{
byte[] buffer = System.Text.Encoding.ASCII.GetBytes(parameter + "\r\n");
networkStream.Write(buffer, 0, buffer.Length);
}
networkStream.Close();
tcpClient.Close();
}
}
}
其中,TcpClient.Connect 方法用于连接 RDP,NetworkStream.Write 方法用于发送 RDP 参数。您需要根据您的 RDP 文件进行相应修改,并将代码嵌入到您的 C# 程序中即可实现连接 RDP 和 RemoteApp。 您好!要使用C#程序连接RDP及RemoteApp需要使用`MSTSCLib`库。
using System;
using System.Windows.Forms;
using MSTSCLib;
namespace RDP_Connection
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void bConnect_Click(object sender, EventArgs e)
{
try
{
// 配置RDP控件参数
axRDPControl.DesktopHeight = 1024;
axRDPControl.DesktopWidth = 1280;
axRDPControl.AdvancedSettings7.SmartSizing = true;
axRDPControl.ColorDepth = 32;
// 设置RDP文件信息
IMsTscNonScriptable secured = (IMsTscNonScriptable)axRDPControl.GetOcx();
secured.ClearTextPassword = "mypassword"; // RDP密码
axRDPControl.Server = "myserver.com"; // RDP server地址
axRDPControl.UserName = "myusername"; // RDP登录用户名
axRDPControl.Domain = null; // RDP登录域
// 使用上面的rdp配置信息链接RDP
axRDPControl.Connect();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void bDisconnect_Click(object sender, EventArgs e)
{
axRDPControl.Disconnect(); // 断开RDP连接
}
}
}
对于RemoteApp连接,建议将其部署在Web服务器中并运行。以下是一个示例:
private void button1_Click(object sender, EventArgs e)
{
MsRdpClient8NotSafeForScripting client = new MsRdpClient8NotSafeForScripting();
client.Server = "myserver.com";
client.AdvancedSettings7.EnableCredSspSupport = true;
client.AdvancedSettings7.AuthenticationLevel = 2;
client.UserName = "myusername";
client.SecuredSettings.FullScreen = false;
//RemoteApp连接
IMsTscNonScriptable secured = (IMsTscNonScriptable)client.GetOcx();
secured.ClearTextPassword = "mypassword"; // RemoteApp登录密码
client.AdvancedSettings8.RDPPort = 3389; // 连接端口,默认为3389
client.AdvancedSettings8.RemoteProgram2 = "rdpinit.exe"; // RemoteApp程序名
client.AdvancedSettings8.RemoteApplicationMode = true; // 启用RemoteApp模式
client.Connect();
}
希望这些代码能够帮助您连接RDP和RemoteApp。谢谢!
求最佳答案{:10_254:} 问题解决了吗 您好!连接 RDP 和 RemoteApp 可以使用 C# 编程语言来实现。以下是一个示例代码,该代码会读取给定的 RDP 文件,并使用指定的参数进行远程连接:
using System;
using System.Diagnostics;
namespace RdpConnectionExample
{
class Program
{
static void Main(string[] args)
{
string rdpFileContent = @"
allow desktop composition:i:1
allow font smoothing:i:1
alternate full address:s:119.91.206.185
alternate shell:s:rdpinit.exe
devicestoredirect:s:*
disableremoteappcapscheck:i:1
drivestoredirect:s:*
full address:s:119.91.206.185
prompt for credentials on client:i:1
promptcredentialonce:i:0
redirectcomports:i:1
redirectdrives:i:1
remoteapplicationmode:i:1
remoteapplicationname:s:AliWorkbench
remoteapplicationprogram:s:||AliWorkbench
span monitors:i:1
use multimon:i:1";
string rdpFilePath = @"C:\path\to\example.rdp";
// 将 RDP 文件内容写入指定文件
System.IO.File.WriteAllText(rdpFilePath, rdpFileContent);
// 使用默认关联程序打开 RDP 文件
Process.Start(rdpFilePath);
}
}
}
请将上述示例代码中的 rpFileContent 替换为您的 RDP 文件内容,并且将 rdpFilePath 替换为希望保存 RDP 文件的路径。运行代码后,它将创建一个 RDP 文件并将其打开。
这只是一个基本的示例,具体的实现取决于您的需求和环境。您可以根据需要进一步定制和扩展代码。
页:
[1]