Skip to content
This repository has been archived by the owner on Jun 23, 2021. It is now read-only.

Commit

Permalink
增加仅打开远程程序的功能
Browse files Browse the repository at this point in the history
  • Loading branch information
xunki committed Feb 9, 2018
1 parent b099cc9 commit 2a7e34b
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 16 deletions.
34 changes: 31 additions & 3 deletions RdpTest/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
Expand Down Expand Up @@ -40,10 +41,10 @@ private void LoadHostConfig()
panelBody.Controls.Clear(); //清空原有

var hosts = (List<RemoteHost>)Db.Connection.Query<RemoteHost>(
"SELECT Id,Name,Address,Port,User,Pwd,Sort,ParentId FROM RemoteHost");
"SELECT Id,Name,Address,Port,User,Pwd,Sort,ParentId,RemoteProgram FROM RemoteHost");

//创建分组
foreach (var hostGroup in hosts.Where(x => x.ParentId == 0).OrderBy(x => x.Sort))
foreach (var hostGroup in hosts.Where(x => x.ParentId == 0).OrderByDescending(x => x.Sort))
{
//建立分组
var hostGroupBox = new HostGroupBox { Dock = DockStyle.Top, Height = 100, Text = hostGroup.Name };
Expand Down Expand Up @@ -99,6 +100,34 @@ void ConnectRemoteHost(object sender, EventArgs e)
rdpClient.UserName = host.User;
rdpClient.AdvancedSettings2.ClearTextPassword = host.Pwd;

//进运行远程程序模式
if (!string.IsNullOrEmpty(host.RemoteProgram))
{
rdpClient.RemoteProgram2.RemoteProgramMode = true;
rdpClient.Width = Screen.PrimaryScreen.Bounds.Width;
rdpClient.Height = Screen.PrimaryScreen.Bounds.Height;
rdpClient.OnLoginComplete += (o, args) =>
{
rdpClient.RemoteProgram2.ServerStartProgram(host.RemoteProgram, "", "%SYSTEMROOT%", false, "", false);
rdpClient.OnRemoteProgramResult += (o1, args1) =>
{
if (args1.lError != RemoteProgramResult.remoteAppResultOk)
{
rdpClient.Dispose();
MessageBox.Show(args1.lError.ToString(), "打开远程程序失败");
}
};

tabMain.TabPages.Remove(page);
};
}

//rdpClient.RemoteProgram2.RemoteProgramMode = true;
//rdpClient.OnLoginComplete += (o, args) =>
//{
// rdpClient.RemoteProgram2.ServerStartProgram("cmd", "", "%SYSTEMROOT%", false, "", false);
// tabMain.TabPages.Remove(page);
//};

/* 因为分辨率比例问题,缩放效果并不怎么样
rdpClient.Width = Screen.PrimaryScreen.Bounds.Width;
Expand All @@ -117,7 +146,6 @@ void ConnectRemoteHost(object sender, EventArgs e)
rdpClient.Connect();
}


#region 菜单按钮
private void btnChangeStyle_Click(object sender, EventArgs e)
{
Expand Down
2 changes: 1 addition & 1 deletion RdpTest/Model/RemoteHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class RemoteHost
public int Sort { get; set; }
public int ParentId { get; set; }


public string RemoteProgram { get; set; }

}
}
2 changes: 1 addition & 1 deletion RdpTest/RdpTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>x86</PlatformTarget>
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
Expand Down
15 changes: 13 additions & 2 deletions RdpTest/RemoteHostForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,16 @@ private void LoadRemoteHost()
numPort.Value = RemoteHost.Port;
txtUser.Text = RemoteHost.User;
txtPwd.Text = RemoteHost.Pwd;
txtRemoteProgram.Text = RemoteHost.RemoteProgram;

lbCopy.Visible = true; //显示复制按钮
}

private void lbCopy_Click(object sender, EventArgs e)
{
RemoteHost = null;
lbCopy.Visible = false;
}

private void cbIsParent_CheckedChanged(object sender, System.EventArgs e)
{
Expand Down Expand Up @@ -110,16 +118,19 @@ private void btnSave_Click(object sender, System.EventArgs e)
host.Port = Convert.ToInt32(numPort.Value);
host.User = txtUser.Text.Trim();
host.Pwd = txtPwd.Text;
host.RemoteProgram = txtRemoteProgram.Text.Trim();
}

Db.Connection.Execute(
IsModify
? "UPDATE RemoteHost SET Name=@Name,Address=@Address,Port=@Port,User=@User,Pwd=@Pwd,Sort=@Sort,ParentId=@ParentId WHERE Id=" + RemoteHost.Id
: "INSERT INTO RemoteHost(Name,Address,Port,User,Pwd,Sort,ParentId) VALUES(@Name,@Address,@Port,@User,@Pwd,@Sort,@ParentId)",
? "UPDATE RemoteHost SET Name=@Name,Address=@Address,Port=@Port,User=@User,Pwd=@Pwd,Sort=@Sort,ParentId=@ParentId,RemoteProgram=@RemoteProgram WHERE Id=" + RemoteHost.Id
: "INSERT INTO RemoteHost(Name,Address,Port,User,Pwd,Sort,ParentId,RemoteProgram) VALUES(@Name,@Address,@Port,@User,@Pwd,@Sort,@ParentId,@RemoteProgram)",
host);


DialogResult = DialogResult.OK;
}


}
}
56 changes: 47 additions & 9 deletions RdpTest/RemoteHostForm.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified RdpTest/Resources/config.wdb
Binary file not shown.

0 comments on commit 2a7e34b

Please sign in to comment.