Solved

RPC implementation to start windows messenger service and send a message.

Posted on 2004-04-27
18
241 Views
Last Modified: 2010-05-18
Hi all,
Can anyone give me Remote Procedure Call implentation  in VC++ for starting messenger service on any IP address.Then it sends message(something like net send) to the IP using RPC.
0
Comment
Question by:novice_expert
  • 7
  • 7
  • 3
18 Comments
 
LVL 3

Assisted Solution

by:a_pravarakhya
a_pravarakhya earned 100 total points
ID: 10928001
I saw the information in programmatically sending net send, in the following link:
http://www.codeproject.com/internet/fakesend.asp?df=100&forumid=15730&exp=0&select=684302

The code in this link might help you.


Pravarakhya
0
 
LVL 86

Accepted Solution

by:
jkr earned 100 total points
ID: 10928522
I don't know why you explicitly mention RPC (which is used "uder the hood" anyway), but you'd usually use 'NetMessageBufferSend()' for that:

http://win32.mvps.org/network/nmbs.cpp

#include <windows.h>
#include <lm.h>
#include <stdio.h>
#include <stdlib.h>
#pragma hdrstop
#pragma comment( lib, "netapi32.lib" )



#define MAXLEN 256



void enum_names( const wchar_t *server );



int main( int argc, char *argv[] )
{
      DWORD rc;
      wchar_t server[MAXLEN], name[MAXLEN], from[MAXLEN], msg[MAXLEN];

      if ( argc != 5 && argc != 2 )
      {
            puts( "\nusage: nmbs \\\\server message-name from-name \"message\"" );
            puts( "       nmbs \\\\server\n" );
            puts( "First form: Sends the message to the <message-name> alias on <server>." );
            puts( "       Use whatever you like as <fromname>." );
            puts( "Second form: Lists <message-name>s on <server>. Note that not all of" );
            puts( "       them may work." );

            return 1;
      }

      mbstowcs( server, argv[1], MAXLEN );
      server[MAXLEN - 1] = L'\0';

      if ( argc == 2 )
      {
            enum_names( server );
      }
      else
      {
            mbstowcs( name, argv[2], MAXLEN );
            name[MAXLEN - 1] = L'\0';
            mbstowcs( from, argv[3], MAXLEN );
            from[MAXLEN - 1] = L'\0';
            mbstowcs( msg, argv[4], MAXLEN );
            msg[MAXLEN - 1] = L'\0';

            printf( "\nTrying ... " );
            rc = NetMessageBufferSend( server, name, from, (byte *) &msg[0], wcslen( msg ) * 2 );

            if ( rc != NERR_Success )
            {
                  printf( "NMBS() returned %lu\n", rc );
                  return 1;
            }

            puts( "Done." );
      }

      return 0;
}



void enum_names( const wchar_t *server )
{
      MSG_INFO_1 *buf, *cur;
      DWORD read, total, resumeh, rc, i;

      printf( "\nAvailable message-names on server %S:\n", server );
      resumeh = 0;
      do
      {
            buf = NULL;
            rc = NetMessageNameEnum( server, 1, (BYTE **) &buf,
                  512, &read, &total, &resumeh );
            if ( rc != ERROR_MORE_DATA && rc != ERROR_SUCCESS )
                  break;

            for ( i = 0, cur = buf; i < read; ++ i, ++ cur )
            {
                  // Note: the capital S in the format string will expect Unicode
                  // strings, as this is a program written/compiled for ANSI.
                  printf( "%S\n", cur->msgi1_name );
            }

            if ( buf != NULL )
                  NetApiBufferFree( buf );

      } while ( rc == ERROR_MORE_DATA );

      if ( rc != ERROR_SUCCESS )
            printf( "NMNE() returned %lu\n", rc );
}


0
 
LVL 3

Author Comment

by:novice_expert
ID: 10935495
I think the above code does not display a MessageBox with Message as seen in net send command.Also,can I mention any IP address as server or it means to be on same domain.Anyhow,what I need is it must work for any IP Address.OK,how can I know if messenger service is currently installed on remote system.If you can suggest any way to start it if its not there,that will be fabulous.What data tranfer happens to achieve the same?
0
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.

 
LVL 3

Expert Comment

by:a_pravarakhya
ID: 10935610
The link I have mentioned before answers all your questions:
http://www.codeproject.com/internet/fakesend.asp?df=100&forumid=15730&exp=0&select=684302
0
 
LVL 3

Author Comment

by:novice_expert
ID: 10937658
That is using MailSlots which does not ensure if the message was sent or not as its one way communication.I want duplex communication like Named Pipes  RPC implementation to send message and confirm delivery of message.
0
 
LVL 3

Author Comment

by:novice_expert
ID: 10937662
That too using UDP port 135.
0
 
LVL 3

Expert Comment

by:a_pravarakhya
ID: 10937926
Messenger has its own protocol implementation and I think mailslots are the means to send the messege using messenger service.
You cannot use UDP to confirm the delivery of the message.So you need to implement your own service if you want to have a confirmation of delivery using TCP.

Thanks,
Pravarakhya
0
 
LVL 3

Author Comment

by:novice_expert
ID: 10937971
It can be done.But I don't know how?If you can provide code to achieve using Named Pipes for sending message that will be helpful.
0
 
LVL 3

Expert Comment

by:a_pravarakhya
ID: 10938025
This very good article has info about sending netsend messages and has source code, perhaps with named pipes.
http://www.codeproject.com/internet/anetsend.asp
0
 
LVL 3

Author Comment

by:novice_expert
ID: 10938207
It uses NetMessageBufferSend not named pipes:((
0
 
LVL 86

Expert Comment

by:jkr
ID: 10941883
>>I think the above code does not display a MessageBox with Message as seen in net send command

Don't think, try it. It will. :o)

>>Also,can I mention any IP address as server

That depends on the transport. But, usually, any address will do.
0
 
LVL 3

Author Comment

by:novice_expert
ID: 10947280
OK jkr,
But NetMessageBufferSend does not confirm if message was sent successfully.
0
 
LVL 86

Expert Comment

by:jkr
ID: 10952963
>>But NetMessageBufferSend does not confirm if message was sent successfully.

If the function returns without an error, the message was transmitted successfully. Ssshh, here I'm telling you a secret: 'net send' uses this API internally :o)
0
 
LVL 3

Expert Comment

by:a_pravarakhya
ID: 10957055
I agree with jkr. 'net send' uses this API internally. forget named pipes, just follow this link I mentioned before:
http://www.codeproject.com/internet/anetsend.asp
0
 
LVL 3

Author Comment

by:novice_expert
ID: 10957173
OK one more query if I want to send message at 10.0.0.3@main ip address i.e. 10.0.0.3 is LAN ip at this domain.Will it allow this?
0
 
LVL 3

Expert Comment

by:a_pravarakhya
ID: 10957308
See, you are able to do that with a "net send" command, you can do it with the code :)
0
 
LVL 3

Expert Comment

by:a_pravarakhya
ID: 10957376
See, if you are able to do that with a "net send" command, you can do it with the code :)
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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

766 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