DelphiFAQ Home Search:

API-function for console command NET SEND

 

commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

Question:

Is there an API-function for the console command NET SEND (from Windows NT)
NET SEND {name | * | /DOMAIN[:name] | /USERS} message


Answer:

NET SEND uses named pipes. The sample program below links to function NetMessageBufferSend in the 'NETAPI32.DLL' library.

program Dummy;

function NetSend(Dest, Source, Msg: string) : Longint; overload;
type
  TNetMessageBufferSendFunction = function(servername, msgname, fromname: PWideChar;
               Buf: PWideChar; buflen: Cardinal) : Longint; stdcall;
var
  NetMessageBufferSend: TNetMessageBufferSendFunction;
  SourceWideChar: PWideChar;
  DestWideChar: PWideChar;
  MessagetextWideChar: PWideChar;
  Handle: THandle;
begin { NetSend }
  Handle := LoadLibrary('NETAPI32.DLL');
  if Handle=0 then
  begin
    Result := GetLastError;
    Exit;
  end; { Handle=0 }
  @NetMessageBufferSend := GetProcAddress(Handle, 'NetMessageBufferSend');
  if @NetMessageBufferSend=nil then
  begin
    Result := GetLastError;
    Exit;
  end; { @NetMessageBufferSend=nil }
  MessagetextWideChar := nil;
  SourceWideChar := nil;
  DestWideChar := nil;

  try
    GetMem(MessagetextWideChar, Length(Msg)*SizeOf(WideChar)+
           1);
    GetMem(DestWideChar, 20*SizeOf(WideChar)+1);
    StringToWideChar(Msg, MessagetextWideChar, Length(Msg)*SizeOf(WideChar)+
                     1);
    StringToWideChar(Dest, DestWideChar, 20*SizeOf(WideChar)+
                     1);
    if Source='' then
      Result := NetMessageBufferSend(nil, DestWideChar, nil, MessagetextWideChar,
                                     Length(Msg)*SizeOf(WideChar)+
                                     1)
    else
    begin
      GetMem(SourceWideChar, 20*SizeOf(WideChar)+1);
      StringToWideChar(Source, SourceWideChar, 20*SizeOf(WideChar)+
                       1);
      Result := NetMessageBufferSend(nil, DestWideChar, SourceWideChar,
                                     MessagetextWideChar, Length(Msg)*SizeOf(WideChar)
                                     +1);
      FreeMem(SourceWideChar);
    end; { not (Source='') }

  finally
    FreeMem(MessagetextWideChar);
    FreeLibrary(Handle);
  end; { try }
end; { NetSend }

function NetSend(Dest, Msg: string) : Longint; overload;
begin { NetSend }
  Result := NetSend(Dest, '', Msg);
end; { NetSend }

function NetSend(Msg: string) : Longint; overload;
begin { NetSend }
  Result := NetSend('', '', Msg);
end; { NetSend }

begin
  NetSend('Mike', 'Hello, Mike');
end.
You don't like the formatting? Check out SourceCoder then!

Comments:

2006-10-09, 02:30:59
anonymous from Japan  
How to received message from net send ?
2008-07-06, 03:36:02
anonymous from Germany  
yxs

Keywords:

2009-01-02, 08:34:16
heavymagic@gmail.com from Turkey  
to domain message?

 

 

Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option.
 
It seems that you are
from Los Angeles, US .

Info/ Feedback on this

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:
photo Add a picture:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity. The owner of this web site reserves the right to delete such material.