在程序中如何调用windows的net send命令(在线等待)(50分)

  • 主题发起人 主题发起人 hellobaobao
  • 开始时间 开始时间
H

hellobaobao

Unregistered / Unconfirmed
GUEST, unregistred user!
在程序中如何调用windows的net send命令向局域网中的用户发送信息
我这个程序将安装在公司的服务器上,程序将定期访问数据库,如果数据有错误
则向前台的客户端发送消息.如何实现?
 
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
function WinExecAndWait32(FileName:String; Visibility : integer): DWORD;
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
function TForm1.WinExecAndWait32(FileName:String; Visibility : integer): DWORD;
var
zAppName:array[0..512] of char;
zCurDir:array[0..255] of char;
WorkDir:String;
StartupInfo:TStartupInfo;
ProcessInfo:TProcessInformation;
begin
StrPCopy(zAppName,FileName);
GetDir(0,WorkDir);
StrPCopy(zCurDir,WorkDir);
FillChar(StartupInfo,Sizeof(StartupInfo),#0);
StartupInfo.cb := Sizeof(StartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow := Visibility;
if not CreateProcess(
nil,
zAppName, { pointer to command line string }
nil, { pointer to process security attributes }
nil, { pointer to thread security attributes }
false, { handle inheritance flag }
CREATE_NEW_CONSOLE or { creation flags }
NORMAL_PRIORITY_CLASS,
nil, { pointer to new environment block }
nil, { pointer to current directory name }
StartupInfo, { pointer to STARTUPINFO }
ProcessInfo { pointer to PROCESS_INF }
)
then Result := $FFFFFFFF else begin
WaitforSingleObject(ProcessInfo.hProcess,INFINITE);
GetExitCodeProcess(ProcessInfo.hProcess,Result);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
WinExecAndWait32('net send deer ok',SW_NORMAL);//deer为机器名  ok为要传的内容

end;

end.
 
给个函数:
function NetMessageBufferSend(servername: PWideChar; msgname: PWideChar; fromname: PWideChar; buf: PWideChar; buflen: DWORD): DWORD; stdcall; external 'netapi32.dll'

调用方法:
NetMessageBufferSend(nil, pwidechar(Addr), nil, PWideChar(Msg), length(msg) * 2);
Addr是对方地址或机器名,Msg是文字信息
 
程序从一个ini文件中读取对方的ip(有多个ip)以达到同时向多个ip发送信息,我用winexec来实现,但是无法正常执行.
for Ifor:=1 to IPcount do
begin
StrIP:='';
j:=inttostr(Ifor);
StrIP:=ADOConnIni.Readstring('IP地址',j,'');
Winexec('NET SEND'+'''StrIP'''+'ceshi',0);//无法正常执行
end;
AdoConnIni 是一个TIniFile类,strIP是一个变量存储ip地址.
 
ini文件的结构如下:
[IP地址]
IP个数=2
1=192.168.0.181
2=192.168.0.188
 
接受答案了.
 
后退
顶部