Solved

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

Posted on 2004-04-27
18
232 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 3

Expert Comment

by:a_pravarakhya
Comment Utility
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
Comment Utility
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
Comment Utility
That too using UDP port 135.
0
 
LVL 3

Expert Comment

by:a_pravarakhya
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 3

Expert Comment

by:a_pravarakhya
Comment Utility
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
Comment Utility
It uses NetMessageBufferSend not named pipes:((
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
>>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
Comment Utility
OK jkr,
But NetMessageBufferSend does not confirm if message was sent successfully.
0
 
LVL 86

Expert Comment

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

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now