function NetMessageBufferSend(Servername, MsgName, FromName, Buf: PWideChar; var BufLen: Integer): Integer;stdcall;var MainForm: TMainForm;implementation{$R *.dfm}function NetMessageBufferSend; external 'netapi32.dll' name 'NetMessageBufferSend';function TMainForm.SendMsg(Toh,From,Msg: string): integer; var ToName: array [0..64] of WideChar; FromName: array [0..64] of WideChar; WMsgText: array [0..1000] of WideChar; MsgLen, i: Integer; begin for i := 0 to 64 do begin ToName[i] :=#0; FromName[i] := #0; end; StringToWideChar(Toh, ToName, MsgLen); StringToWideChar(From, FromName, MsgLen); for i := 0 to 1000 do WMsgText[i] := #0; StringToWideChar(Msg, WMsgText, MsgLen); Result := NetMessageBufferSend(nil, ToName, nil, WMsgText, MsgLen); end;procedure TMainForm.SendBitBtnClick(Sender: TObject); var res : integer; begin if AdrComboBox.Text <> '' then begin StatusLabel.Caption := 'Wait...'; Update; if AdrComboBox.Items.IndexOf(AdrComboBox.Text) = -1 then begin if AdrComboBox.Items.Count > 20 then AdrComboBox.Items.Delete(0); AdrComboBox.Items.Add(AdrComboBox.Text); end; res := SendMsg(AdrComboBox.Text, '', MsgText.Text); case res of 0 : StatusLabel.Caption := 'The message is sent'; 87 : StatusLabel.Caption := 'The parameter is incorrect'; 123 : StatusLabel.Caption := 'sintax is incorrect'; 2273 : StatusLabel.Caption := 'Can not find'+ AdrComboBox.Text; else StatusLabel.Caption := 'Error: '+IntToStr(res); end; end; end;end.
use ShellAPiShell('net send ' + HostName + 'SendInfo');
给分呀:)
unit MainUnit;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls;type
TMainForm = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
StatusLabel: TPanel;
Panel4: TPanel;
Label1: TLabel;
AdrComboBox: TComboBox;
Panel5: TPanel;
MsgText: TMemo;
SendBitBtn: TBitBtn;
AboutBitBtn: TBitBtn;
ExitBitBtn: TBitBtn;
procedure SendBitBtnClick(Sender: TObject);
private
{ Private declarations }
public
function SendMsg(Toh, From, Msg: string): Integer;
{ Public declarations }
end;
function NetMessageBufferSend(Servername, MsgName, FromName, Buf: PWideChar;
var BufLen: Integer): Integer;stdcall;var
MainForm: TMainForm;implementation{$R *.dfm}function NetMessageBufferSend; external 'netapi32.dll' name 'NetMessageBufferSend';function TMainForm.SendMsg(Toh,From,Msg: string): integer;
var
ToName: array [0..64] of WideChar;
FromName: array [0..64] of WideChar;
WMsgText: array [0..1000] of WideChar;
MsgLen, i: Integer;
begin
for i := 0 to 64 do
begin
ToName[i] :=#0;
FromName[i] := #0;
end;
StringToWideChar(Toh, ToName, MsgLen);
StringToWideChar(From, FromName, MsgLen);
for i := 0 to 1000 do WMsgText[i] := #0;
StringToWideChar(Msg, WMsgText, MsgLen);
Result := NetMessageBufferSend(nil, ToName, nil, WMsgText, MsgLen);
end;procedure TMainForm.SendBitBtnClick(Sender: TObject);
var
res : integer;
begin
if AdrComboBox.Text <> '' then
begin
StatusLabel.Caption := 'Wait...';
Update;
if AdrComboBox.Items.IndexOf(AdrComboBox.Text) = -1 then
begin
if AdrComboBox.Items.Count > 20 then
AdrComboBox.Items.Delete(0);
AdrComboBox.Items.Add(AdrComboBox.Text);
end;
res := SendMsg(AdrComboBox.Text, '', MsgText.Text);
case res of
0 : StatusLabel.Caption := 'The message is sent';
87 : StatusLabel.Caption := 'The parameter is incorrect';
123 : StatusLabel.Caption := 'sintax is incorrect';
2273 : StatusLabel.Caption := 'Can not find'+ AdrComboBox.Text;
else
StatusLabel.Caption := 'Error: '+IntToStr(res);
end;
end;
end;end.