delphi的远程控制没人会吗?(1分)

  • 主题发起人 主题发起人 newyj
  • 开始时间 开始时间
N

newyj

Unregistered / Unconfirmed
GUEST, unregistred user!
remote debug 能用码?
 
给你提供一篇文章,看看有没有用:
  在网络管理中,有时需要通过监视远程计算机屏幕来了解网上微机的使用情况。
虽然,市面上有很多软件可以实现该功能,有些甚至可以进行远程控制,但在使用上缺乏
灵活性,如无法指定远程计算机屏幕区域的大小和位置,进而无法在一屏上同时监视多个
屏幕。其实,可以用Delphi自行编制一个灵活的远程屏幕抓取工具,简述如下。

  一、软硬件要求

  Windows95/98对等网,用来监视的计算机(以下简称主控机)和被监视的计算机
(以下简称受控机)都必须装有TCP/IP 协议,并正确配置。如没有网络,也可以在一
台计算机上进行调试。

  二、实现方法

  编制两个应用程序,一个为VClient.exe,装在受控机上,另一个为VServer.exe,
装在主控机上。VServer.exe指定要监视的受控机的IP地址和将要在受控机屏幕上抓取
区域的大小和位置,并发出屏幕抓取指令给VClient.exe,VClient.exe得到指令后,
在受控机屏幕上选取指定区域,生成数据流,将其发回主控机,并在主控机上显示
出抓取区域的BMP图象。由以上过程可以看出,该方法的关键有二:一是如何在受控
机上进行屏幕抓取,二是如何通过TCP/IP协议在两台计算机中传输数据。
  UDP(User Datagram Protocol,意为用户报文协议)是Internet上广泛采用
的通信协议之一。与TCP协议不同,它是一种非连接的传输协议,没有确认机制,
可靠性不如TCP,但它的效率却比TCP高,用于远程屏幕监视还是比较适合的。
同时,UDP控件不区分服务器端和客户端,只区分发送端和接收端,编程上较为简单,
故选用UDP协议,使用Delphi 4.0提供的TNMUDP控件。

  三、创建演示程序

  第一步,编制VClient.exe文件。新建Delphi工程,将默认窗体的Name属性设为
“Client”。加入TNMUDP控件,Name属性设为“CUDP”;LocalPort属性设为“1111”,
让控件CUDP监视受控机的1111端口,当有数据发送到该口时,触发控件CUDP的
OnDataReceived事件;RemotePort属性设为“2222”,当控件CUDP发送数据时,
将数据发到主控机的2222口。
  在implementation后面加入变量定义

const BufSize=2048;{ 发送每一笔数据的缓冲区大小 }
var
BmpStream:TMemoryStream;
LeftSize:Longint;{ 发送每一笔数据后剩余的字节数 }

为Client的OnCreate事件添加代码:
procedure TClient.FormCreate(Sender: TObject);
begin
BmpStream:=TMemoryStream.Create;
end;

为Client的OnDestroy事件添加代码:
procedure TClient.FormDestroy(Sender: TObject);
begin
BmpStream.Free;
end;

为控件CUDP的OnDataReceived事件添加代码:
procedure TClient.CUDPDataReceived(Sender: TComponent;
NumberBytes: Integer; FromIP: String);
var
CtrlCode:array[0..29] of char;
Buf:array[0..BufSize-1] of char;
TmpStr:string;
SendSize,LeftPos,TopPos,RightPos,BottomPos:integer;
begin
CUDP.ReadBuffer(CtrlCode,NumberBytes);{ 读取控制码 }
if CtrlCode[0]+CtrlCode[1]+CtrlCode[2]+CtrlCode[3]='show' then
begin { 控制码前4位为“show”表示主控机发出了抓屏指令 }
if BmpStream.Size=0 then { 没有数据可发,必须截屏生成数据 }
begin
TmpStr:=StrPas(CtrlCode);
TmpStr:=Copy(TmpStr,5,Length(TmpStr)-4);
LeftPos:=StrToInt(Copy(TmpStr,1,Pos(':',TmpStr)-1));
TmpStr:=Copy(TmpStr,Pos(':',TmpStr)+1,Length(TmpStr)
-Pos(':',TmpStr));
TopPos:=StrToInt(Copy(TmpStr,1,Pos(':',TmpStr)-1));
TmpStr:=Copy(TmpStr,Pos(':',TmpStr)+1,Length(TmpStr)-
Pos(':',TmpStr));
RightPos:=StrToInt(Copy(TmpStr,1,Pos(':',TmpStr)-1));
BottomPos:=StrToInt(Copy(TmpStr,Pos(':',TmpStr
)+1,Length(TmpStr)-Pos(':',TmpStr)));
ScreenCap(LeftPos,TopPos,RightPos,BottomPos); {
截取屏幕 }
end;
if LeftSize>BufSize then SendSize:=BufSize
else SendSize:=LeftSize;
BmpStream.ReadBuffer(Buf,SendSize);
LeftSize:=LeftSize-SendSize;
if LeftSize=0 then BmpStream.Clear;{ 清空流 }
CUDP.RemoteHost:=FromIP; { FromIP为主控机IP地址 }
CUDP.SendBuffer(Buf,SendSize); { 将数据发到主控机的2222口 }
end;
end;

其中ScreenCap是自定义函数,截取屏幕指定区域,
代码如下:
procedure TClient.ScreenCap(LeftPos,TopPos,
RightPos,BottomPos:integer);
var
RectWidth,RectHeight:integer;
SourceDC,DestDC,Bhandle:integer;
Bitmap:TBitmap;
begin
RectWidth:=RightPos-LeftPos;
RectHeight:=BottomPos-TopPos;
SourceDC:=CreateDC('DISPLAY','','',nil);
DestDC:=CreateCompatibleDC(SourceDC);
Bhandle:=CreateCompatibleBitmap(SourceDC,
RectWidth,RectHeight);
SelectObject(DestDC,Bhandle);
BitBlt(DestDC,0,0,RectWidth,RectHeight,SourceDC,
LeftPos,TopPos,SRCCOPY);
Bitmap:=TBitmap.Create;
Bitmap.Handle:=BHandle;
BitMap.SaveToStream(BmpStream);
BmpStream.Position:=0;
LeftSize:=BmpStream.Size;
Bitmap.Free;
DeleteDC(DestDC);
ReleaseDC(Bhandle,SourceDC);
end;
存为“C:/VClient/ClnUnit.pas”和“C:/VClient/VClient.dpr”,
并编译。

  第二步,编制VServer.exe文件。新建Delphi工程,将窗体的Name属性设为
“Server”。加入TNMUDP控件,Name属性设为“SUDP”;LocalPort属性设为“2222”,
让控件SUDP监视主控机的2222端口,当有数据发送到该口时,触发控件SUDP的
OnDataReceived事件;RemotePort属性设为“1111”,当控件SUDP发送数据时,
将数据发到受控机的1111口。加入控件Image1,Align属性设为“alClient”;
加入控件Button1,Caption属性设为“截屏”;加入控件Label1,Caption属性设为
“左:上:右:下”;加入控件Edit1,Text属性设为“0:0:100:100”;加入控件
Label2,Caption属性设为“受控机IP地址”;加入控件Edit2,Text属性设为
“127.0.0.1”; 在implementation后面加入变量定义
const BufSize=2048;
var
RsltStream,TmpStream:TMemoryStream;

为Server的OnCreate事件添加代码:
procedure TServer.FormCreate(Sender: TObject);
begin
RsltStream:=TMemoryStream.Create;
TmpStream:=TMemoryStream.Create;
end;

为Client的OnDestroy事件添加代码:
procedure TServer.FormDestroy(Sender: TObject);
begin
RsltStream.Free;
TmpStream.Free;
end;

为控件Button1的OnClick事件添加代码:
procedure TServer.Button1Click(Sender: TObject);
var ReqCode:array[0..29] of char;ReqCodeStr:string;
begin
ReqCodeStr:='show'+Edit1.Text;
StrpCopy(ReqCode,ReqCodeStr);
TmpStream.Clear;
RsltStream.Clear;
SUDP.RemoteHost:=Edit2.Text;
SUDP.SendBuffer(ReqCode,30);
end;

为控件SUDP的OnDataReceived事件添加代码:
procedure TServer.SUDPDataReceived(Sender: TComponent;
NumberBytes: Integer; FromIP: String);
var ReqCode:array[0..29] of char;ReqCodeStr:string;
begin
ReqCodeStr:='show'+Edit1.text;
StrpCopy(ReqCode,ReqCodeStr);
SUDP.ReadStream(TmpStream);
RsltStream.CopyFrom(TmpStream,NumberBytes);
if NumberBytes< BufSize then { 数据已读完 }
begin
RsltStream.Position:=0;
Image1.Picture.Bitmap.LoadFromStream(RsltStream);
TmpStream.Clear;
RsltStream.Clear;
end
else
begin
TmpStream.Clear;
ReqCode:='show';
SUDP.RemoteHost:=Edit2.Text;
SUDP.SendBuffer(ReqCode,30);
end;
end;

存为“C:/VServer/SvrUnit.pas”和
“C:/VServer/VServer.dpr”,并编译。

  四、测试。
  1、本地机测试:在本地机同时运行Vserver.exe和VClient.exe,
利用程序的默认设置,即可实现截屏。查看“控制面板”-“网络”-“TCP/IP”
-“IP地址”,将程序的“客户IP地址”设为该地址 ,同样正常运行。
  2、远程测试:选一台受控机,运行VClient.exe;另选一台主控机,
运行VServer.exe,将“受控机IP地址”即Edit2的内容设为受控机的IP地址,
“截屏”即可。以上简要介绍了远程屏幕抓取的实现方法,至于在主控机上一
屏同时监视多个受控机,读者可自行完善。以上程序,在Windows98对等网、
Delphi 4.0下调试通过。

 
你要的到底是远程控制还是远程调试?
 
我要远程调试
 
那么你还不如加一个冰河,方便,不过也可以说一下,冰河的基本原理就是在服务器端
的进程中开放一个TCP端口客户端发送消息,服务器端接受到不同的消息做不同的事情
方便点还是下一个冰河去好了,如果你真要自己写得去搞懂一大堆API函数,远程控制
得用Hook技术
 
重装了一遍 remote debug 问题解决了。
本机 pc1 remote pc2
文件存放在pc2 的 c:/newyj 共享之。文件 test.exe
Project|Options|Linker 选e remote debug symbols
设置 Run|Parameters|Remote c:/newyj/test.exe
Run|Parameters|Remote //pc2
就可以了其实我就是看了一下安装时的说明。。。
==============================================
DELPHI/C++BUILDER REMOTE DEBUGGING NOTES
===============================================

These notes explain how to use remote debugging
with C++Builder or Delphi. Run this setup program
on all systems where remote programs will be
running. The Delphi or C++Builder IDE is not
required on remote machines.

On Windows NT, the Remote Debugging service can
be run either as a program or as a service. On
Windows 95 or Windows 98, the Remote Debugging
service can only be run as a program. To run as
a program, run "borrdg50.exe -listen" from either
a DOS box or a shortcut. If installed as a service,
communication between the debugger and the remote
application is handled automatically.

To start a remote debugging session, use the IDE
on your local machine and set the following options:

For Delphi only:

Project|Options|Linker
Include remote debug symbols box must be checked.

Project|Options|Directories/Conditionals
Output directory can be set to a shared directory
on the remote machine. If you do not set this up,
you need to copy the .exe and .rsm files onto the
remote machine.

For C++Builder only:

Project|Options|Directories/Conditionals
Final output directory can be set to a shared
directory on the remote machine. If you do not
set this up, you need to copy the .exe and .tds
files onto the remote machine.

For either product:

Run|Parameters|Remote
Set the Remote Path to the remote directory and
.exe name. Example: d:/temp/proj1.exe, where
d:/temp is a directory on the remote machine.
The drive and directory do not have to match the
project directory on the local machine.

Run|Parameters|Remote
Set the Remote Host to the DNS machine name or
to the IP address of the machine on which you
installed the remote debugger server. If you
check Debug project on remote machine and click
OK, all debugger commands start a remote
debugging session for the current project. If
you do not check this option, you must click
the Load button on this dialog to start a remote
debugging session. This also lets you debug an
.exe that is already set up on the remote
machine without having to open the project
associated with it.

IMPORTANT:

The default installation location for the remote
debugging library file BORDBK50.DLL is:
<drive>/<Windows/system32>/Common Files/
Borland Shared/Debugger

The file is installed to this location even if you
choose a different location for the other debugger
files during the installation process. (All other
remote debugger files are installed to a 'bin'
directory under the directory you choose.)

The only case in which BORDBK50.DLL is installed
elsewhere is when the file is already installed
and registered to a different location.

===============================================
Copyright (c) 1999 Inprise Corporation.
All rights re
 
接受答案了.
 
后退
顶部