双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

master..xp cmdshell 执行EXE

gcaling2006 gcaling2006 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我的EXE是DELPHI做的,目的是接收SQL触发器传来的字符串,然后通后消息把字符串传给另一个正在运行的程序,
能找到另一个程序的PID(进程ID),但无法找到另一个在运行程序的窗口句柄.因此就无法接收到消息,

后来想到一个办法,把另一个运行的程序运行时窗体的句柄放在一个INI文件中,这样就不用找这个窗口的句柄了,直接读INI就可得到,但调用SendMessage(winhand, WM_COPYDATA, 1, Integer(@Data));仍不能正常传递消息.

发送消息程序
program send;

{$APPTYPE CONSOLE}

uses
Forms,
windows,
sysutils,
Messages,
WinProcs,
inifiles,
all in 'all.pas';

var
Data: tagCOPYDATASTRUCT;
pBuf: PAnsiChar;
MYHWND: THandle;
inifile: TIniFile;
winhand:integer;
{$R *.res}

begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.Run;

begin
if FileExists(Trim(ExtractFilePath(Application.ExeName)+'com.ini')) = True then
begin
Try
inifile := TIniFile.Create(Trim(ExtractFilePath(Application.ExeName))+'com.ini');
winhand:= strtoint(inifile.ReadString('配置信息','窗口句柄','1'));
Finally
inifile.Free;
end;
end;
GetMem(pBuf, Length(ParamStr(1)) + 1);
try

ZeroMemory(pBuf, Length(ParamStr(1)) + 1);
StrPCopy(pBuf,ParamStr(1));
Data.cbData:= Length(ParamStr(1));
Data.dwData:= Length(ParamStr(1));
Data.lpData:= pBuf;
writeln(ParamStr(1));
SendMessage(winhand, WM_COPYDATA, 1, Integer(@Data));
writeln(winhand);
finally
FreeMem(pBuf);
end;
end;

sleep(3000);
end.

接收消息程序
unit Unit2;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,inifiles;
const
My_MousL=WM_USER+100;
type
TForm2 = class(TForm)
Label1: TLabel;
procedure FormShow(Sender: TObject);
private
j:integer;
{ Private declarations }
public
procedure Mymessage(var t:TMessage);message WM_COPYDATA;

{ Public declarations }
end;

var
Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.FormShow(Sender: TObject);
var inifile:tinifile;
begin
if FileExists(Trim(ExtractFilePath(Application.ExeName)+'com.ini')) = True then
begin
Try
inifile := TIniFile.Create(Trim(ExtractFilePath(Application.ExeName))+'com.ini');
inifile.WriteString('配置信息','窗口句柄',inttostr(findwindow(nil,'form2')));
Finally
inifile.Free;
end;
end
end;

procedure Tform2.Mymessage(var t: TMessage);
var
Data : ^tagCOPYDATASTRUCT;
strMSG: string;
mylen:integer;
begin
Data:= Pointer(t.LParam);
mylen:=integer(data.cbData);
strMSG:= copy(PAnsichar(Data.lpData),1,mylen);

label1.Caption:=strMsg;

end;


end.
...全文
评论 5
收藏 已收藏
分享
返回顶部
gcaling2006
数据库相关 2,508 成员 88,437 内容