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

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.
LVL 3
novice_expertAsked:
Who is Participating?
 
jkrCommented:
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
 
a_pravarakhyaCommented:
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
 
novice_expertAuthor Commented:
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
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
a_pravarakhyaCommented:
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
 
novice_expertAuthor Commented:
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
 
novice_expertAuthor Commented:
That too using UDP port 135.
0
 
a_pravarakhyaCommented:
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
 
novice_expertAuthor Commented:
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
 
a_pravarakhyaCommented:
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
 
novice_expertAuthor Commented:
It uses NetMessageBufferSend not named pipes:((
0
 
jkrCommented:
>>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
 
novice_expertAuthor Commented:
OK jkr,
But NetMessageBufferSend does not confirm if message was sent successfully.
0
 
jkrCommented:
>>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
 
a_pravarakhyaCommented:
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
 
novice_expertAuthor Commented:
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
 
a_pravarakhyaCommented:
See, you are able to do that with a "net send" command, you can do it with the code :)
0
 
a_pravarakhyaCommented:
See, if you are able to do that with a "net send" command, you can do it with the code :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.