斑竹加:其实netsend这个dos命令,在Win32API中可以用NetMessageBufferSend()函数来实现,函数使用例子如下: -------------------------------------------------------------- unit Unit2;
interface
uses Classes, SysUtils;
type Tmsg4nt = class(TThread) private zmsgname,zfromname,zbuf:string; zres:integer; protected procedure Execute; override; public function NetMsgSend(msgname,fromname,buf:string):integer; end;
function NetMessageBufferSend(servername:PWideChar; msgname:PWideChar; fromname:PWideChar; buf: PWideChar; var buflen:integer):integer;cdecl;
implementation
function NetMessageBufferSend; external 'netapi32.dll' name 'NetMessageBufferSend';
function ToUnicode(str:string;dest:PWideChar):integer; var len:integer; begin StringToWideChar(str,dest,len); Result:=len; end;
{ Tmsg4nt }
procedure Tmsg4nt.Execute; const lname=64; lbuf=1024; var msgname_:array [0..lname-1] of WideChar; buf_:array [0..lbuf-1] of WideChar; buflen_,i:Integer; begin for i:=0 to lname-1 do msgname_[i]:=#0; ToUnicode(zmsgname,msgname_); for i:=0 to lbuf-1 do buf_[i]:=#0; ToUnicode(zbuf,buf_); zres:=NetMessageBufferSend(nil,msgname_,nil,@buf_,buflen_); end;
function Tmsg4nt.NetMsgSend(msgname, fromname, buf: string):integer; begin zmsgname:=msgname; zfromname:=fromname; zbuf:=buf; Execute; result:=zres; end;