#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Posts
    52
    Rep Power
    11

    Broadcast network message


    How can I send a message from the administrator to all (or some) users in the network using Delphi?
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Location
    Romania
    Posts
    173
    Rep Power
    11

    Lightbulb


    **************************
    Here's an example - Hope it helps
    **************************

    unit Unit1;

    interface

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

    type
    TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    end;

    var
    Form1: TForm1;

    implementation

    {$R *.dfm}
    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
    Handle := LoadLibrary('NETAPI32.DLL');
    if Handle = 0 then
    begin
    Result := GetLastError;
    Exit;
    end;
    @NetMessageBufferSend := GetProcAddress(Handle, 'NetMessageBufferSend');
    if @NetMessageBufferSend = nil then
    begin
    Result := GetLastError;
    Exit;
    end;

    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;
    finally
    FreeMem(MessagetextWideChar);
    FreeLibrary(Handle);
    end;
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    NetSend('Silver','Silver','Yoooooooo');
    end;

    end.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Posts
    52
    Rep Power
    11
    Hi,

    I tried you code by just changing the dest and source but I am not getting any messages sent..

    Here is my code:

    NetSend('rahma-j','rahma-j','Yoooooooo');


    Best Regards,
    Jassim Rahma
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Location
    Romania
    Posts
    173
    Rep Power
    11
    This only works on windows nt platforms and it's a replacement of the command line "net send IP/computer_name message", it does not work on Win 95, 98, ME.
    If you are interested in a chat there are a couple of freeware products out there that can do the job.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Posts
    52
    Rep Power
    11
    thanks,


    i don't want chat application.


    I am using Windows XP
  10. #6
  11. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Location
    Romania
    Posts
    173
    Rep Power
    11
    There is a service in Win Xp named "Messenger" that deals with the "net send" ... make sure it is started.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Yugoslavia
    Posts
    3
    Rep Power
    0

    hello


    hello
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Andorra
    Posts
    5
    Rep Power
    0

    hello


    hello

IMN logo majestic logo threadwatch logo seochat tools logo