DELPHI 7 下编译通过
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdUDPBase, IdUDPServer,IdSocketHandle;
type
TForm1 = class(TForm)
Button1: TButton;
IdUDPServer1: TIdUDPServer;
IdUDPServer2: TIdUDPServer;
procedure Controls_close(i:integer);
procedure operatecomputer(statue:longword);
procedure Button1Click(Sender: TObject);
procedure IdUDPServer1UDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
//处理系统关闭请求;
procedure TForm1.Controls_close(i:integer);
begin
case i of
1: begin
if win32platform =ver_platform_win32_windows then
exitwindowsex(ewx_force+ewx_shutdown+ewx_poweroff,32);
if win32platform =ver_platform_win32_NT then
operatecomputer(ewx_poweroff); //ewx_poweroff 为关机 EWX_FORCE
end;
2: begin
if win32platform =ver_platform_win32_windows then
exitwindowsex(ewx_force+ewx_shutdown+ewx_poweroff,32);
if win32platform =ver_platform_win32_NT then
operatecomputer(ewx_reboot); //ewx_reboot 为重启
end;
3: begin
if win32platform =ver_platform_win32_windows then
exitwindowsex(ewx_force+ewx_shutdown+ewx_poweroff,32);
if win32platform =ver_platform_win32_NT then
operatecomputer(ewx_logoff); //ewx_logoff 为注销
end;
4: begin
//
end;
end;
end;
//关闭系统方法;
procedure TForm1.operatecomputer(statue:longword);
var
hToken:THandle;
tkp : TOKEN_PRIVILEGES;
ReturnLength : DWord;
begin
if (not OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES or TOKEN_ALL_ACCESS or TOKEN_QUERY, hToken))then
begin
application.Terminate;
end;
LookupPrivilegeValue(nil,'SeShutdownPrivilege',tkp.Privileges[0].Luid);
tkp.PrivilegeCount := 1;
tkp.Privileges[0].Attributes :=SE_PRIVILEGE_ENABLED;
ReturnLength :=0;
AdjustTokenPrivileges(hToken, FALSE, tkp, 0,nil,ReturnLength);
if (GetLastError() <> ERROR_SUCCESS) then
begin
application.Terminate;
end;
if (not ExitWindowsEx(statue, 0)) then
begin
application.Terminate;
end;
end;
//模拟发送;
procedure TForm1.Button1Click(Sender: TObject);
begin
// Controls_close(1); //1关机 2重启 3注销
IdUDPServer2.Send('192.168.1.123',8111,'$3');
end;
//读取消息;
procedure TForm1.IdUDPServer1UDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
var
buffer: pchar;
i:integer;
begin
ShowMessage(ABinding.PeerIP);
buffer := GetMemory(1024);
AData.Read(buffer^,1024);
i:=strtoint(buffer[1]);//只取第二位的数字
Controls_close(i); //调用Controls_close(i)进行相应的处理
FreeMemory(buffer);
end;
end.
一般的远程控制其实真的就这样简单,有此网管软件中所带有远程草监看工作站的屏幕,其实原理也是类似的,工作站自已进行了屏幕截图,并把图片转换成JPEG流通过udp 或者tcp 等协议传输到服务端,服务端再把图片显现出来,就实现了远程监看屏幕,实际总结一句话:“远程的事,都是自己做的”。
本文来源:未知 作者:佚名