2. 运行delphi 7-->Components-->Import Active Control,在列表中找到下面的Microsoft Terminal Services Active Client 1.0 Type Library (Version 1.0),点击install,你可以选择将其安装到现在的包中,也可以新建一个,选择Into new package-->点击Browser将其保存为D:Program FilesBorlandccrunmstscmstsc.bpk。在Description一栏可以填:Microsoft Terminal Service Control,这个名称将出现在安装完成后的Package列表中。点击OK以后,稍等片刻,系统会提示mstsc.bpl将被编译并且安装,是否继续,点击yes。这时如果一切正常的话,系统将提示有两个编译错误(嘿嘿,我指的是正常情况下),难道是BCB的BUG?提示找不到OlePrecedure的定义。我靠。记忆中有个OleProcedure,一个o,一个e,该不会真的是笔误吧。将两处OlePrecedure换成OleProcedure,再次编译,ok了,编译成功,点击Install安装。
3. 如果上一个步骤成功的话,在组件面板的ActiveX下将多出两个控件:MsTscAx和MsRdpClient,我们主要是利用MsTscAx控件。
4. MsTscAx控件的常用属性和方法:
MsTscAx1.DesktopHeight = 600;// 桌面高度
MsTscAx1.DesktopWidth = 800;// 桌面宽度
MsTscAx1.ConnectingText = 'Welcome! ccrun.';// 在连接前显示的字符串
MsTscAx1.Server = '127.0.0.1';// 连接的服务器地址
MsTscAx1.FullScreen = false; // 窗口/全屏模式
MsTscAx1.ColorDepth = 16;// 画面色深(通常都是256色)
MsTscAx1.UserName = 'administrator';// 登录用户名
MsTscAx1.DisconnectedText = '886,ccrun.';// 断开连接后显示的字符串
MsTscAx1.AdvancedSettings.BitmapPeristence = 1;// 将位图缓存到磁盘
MsTscAx1.AdvancedSettings.Compress = 1;// 启用数据压缩
MsTscAx1.SecuredSettings.set_StartProgram('C:\ccrun\123.exe');// 连接后运行的Shell程序,当关闭此Shell程序后自动断开连接
MsTscAx1.Connect();// 连接
MsTscAx1.Disconnect();// 断开连接
5. 新建一个Project,在Form上拖一个MsTscAx控件,根据上面介绍的属性和方法,相信你在BCB中建立自己的终端服务客户端没问题了。
代码示例:
[delphi] view plaincopy
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, MSTSCLib_TLB, StdCtrls;
type
TForm1 = class(TForm)
btn1: TButton;
msrdpclnt: TMsTscAx;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
var
proj: ImsRdpclientAdvancedSettings; // 定义密码用
p1: IMsRdpClientAdvancedSettingsDisp; // 自定义端口用
begin
msrdpclnt.Server := '127.0.0.1';
if msrdpclnt.AdvancedSettings.QueryInterface(IMsRdpClientAdvancedSettingsDisp, p1) = S_OK then
begin
p1.RDPPort := 3389;
end;
msrdpclnt.UserName := 'administrator';
if msrdpclnt.AdvancedSettings.QueryInterface(ImsRdpclientAdvancedSettings,proj) = S_OK then
begin
proj.Set_ClearTextPassword('123');
end;
msrdpclnt.Connect;
end;
end.
示例2:
[delphi] view plaincopy
unit uRDP;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, MSTSCLib_TLB, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
MsRdpClient: TMsRdpClient;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
MsRdpClient := TMsRdpClient.Create(Self);
with MsRdpClient do
begin
Name := 'MsRdpClient';
Parent := Self;
Left := 0;
Top := 0;
Width := 800;
Height := 600;
TabOrder := 0;
ControlData := {0003000008000200000000000B000000030000000000}; // Dies kennt er nicht
end;
Edit1.BringToFront;
Button1.BringToFront;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
MsRdpClient.Server := Edit1.Text;
MsRdpClient.Domain := GetEnvironmentVariable('USERDNSDOMAIN');
MsRdpClient.UserName := '
MsRdpClient.AdvancedSettings2.ClearTextPassword := '
MsRdpClient.Connect;
end;
end.
6. 编译后的程序发布时必须在目标机器上存在mstscax.dll文件,并且用Regsvr32注册以后才能正常运行。