?
Solved

Message to Windows station

Posted on 2005-05-06
7
Medium Priority
?
263 Views
Last Modified: 2010-04-05
Hi,

I need to send a short message to a Windows XP or 2000 station in my LAN.
I don't want to install any software in these stations, so I'm looking for some kind of Windows messenger API in Delphi or any other built-in mechanism in Windows.

My Delphi application can run in a server with full admin privileges, so it's not an issue.

TIA,
Itamar
0
Comment
Question by:itamar
  • 4
  • 3
7 Comments
 
LVL 11

Expert Comment

by:pcsentinel
ID: 13944981
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    procedure SendMsg(Comp, Msg: string);
    { Private declarations }
  public
    { Public declarations }
  end;

function NetMessageBufferSend (
  serverName, msgName, fromName : PWideChar;
  buf : Pointer;
  bufLen : Integer) : DWord; stdcall;

var
  Form1: TForm1;

implementation

function NetMessageBufferSend;      external 'NETAPI32.DLL';

{$R *.DFM}

procedure TForm1.SendMsg(Comp,Msg: string);
var
  lPComp: PWideChar;
  lPSendMsg: PWideChar;
begin
  GetMem(lPComp, 2*Length(Comp)+2);
  GetMem(lPSendMsg, 2*Length(Msg)+2);
       StringToWideChar(Comp, lPComp, Length(Comp)+2);
       StringToWideChar(Msg, lPSendMsg, Length(Msg)+2);
  NetMessageBufferSend(nil, lPComp, nil, lPSendMsg,Length(Msg)*2);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
      SendMsg('paulspc','Test Message');
end;

end.


regards
0
 
LVL 11

Expert Comment

by:pcsentinel
ID: 13945010
By way of explanation the paulspc is the computer name.

Messenger service must be running on the client computer which is normally on by default.

regards

0
 
LVL 16

Accepted Solution

by:
CodedK earned 800 total points
ID: 13949755
uses
........WinSock;   // Add Winsock in USES....
.....
.....
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

function NetSend(Dest, Source, Msg: string) : Longint; overload;
function NetSend(Dest, Msg: string) : Longint; overload;
function NetSend(Msg: string) : Longint; overload;

........
........//Add this code.....

type
  TNetMessageBufferSendFunction = function(servername, msgname, fromname: PWideChar;
               Buf: PWideChar; buflen: Cardinal) : Longint; stdcall;
               
function NetSend(Dest, Source, Msg: string) : Longint; overload;
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;
  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);
    FreeMem(DestWideChar);
    FreeLibrary(Handle);
  End;
end;

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

function NetSend(Msg: String) : Longint; overload;
begin
  Result := NetSend('', '', Msg);
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
//Destination , Source , Message
NetSend(Edit1.Text, Edit2.Text, Edit3.Text);
end;


----------------------------------------------------------------
With these code you can choose the Destination, state ur real name or anything else you like ... and in edit3 text you can write ur message...

The real difference beween this code and pcsentinels code is that pcsentinel uses netsend, and a dos box flashes everytime you sent a message...

Hope this helps... :)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 11

Expert Comment

by:pcsentinel
ID: 13957583
I dont get a dos box on 2K & XP I get a messagebox

regards
0
 
LVL 16

Expert Comment

by:CodedK
ID: 13960389
Sorry Pcsentinel, im sure i read it somewhere on a PAQ in EE. I'll try to find that post..
0
 
LVL 16

Expert Comment

by:CodedK
ID: 13960426
That was based on shellexecute... Sorry my mistake.
0
 
LVL 11

Expert Comment

by:pcsentinel
ID: 13960529
No probs
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month16 days, 13 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question