Recipe 17.11. Sending a Message to Another Computer


Problem

You want to send a pop-up message to one or more users on your network, something they'll see right away without requiring any special third-party applications to be running on their computers.

Solution

Sample code folder: Chapter 17\SendMessage

Use Windows's Net.exe program to send instant messages to named computers on your network.

Discussion

The general syntax of the Net.exe command, when used to send instant messages, is of the form:

 Net.exe Send ComputerName Message 

You'll need to know the name of the computer to which you wish to send the message, or you may use "*" as the computer name to send a message to all computers on your network in one shot. If you specify a domain name as the target address, the message is delivered to all computers belonging to that domain.

You can use this command from a Command Prompt window, or you can use a Visual Basic 2005 application as a wrapper for the command. Create a new Windows Forms application, and add two TextBox controls named TargetComputer and MessageText. Also add a Button control named ActSend, and set its Text property to Send. Add informational labels if desired. The form should look something like Figure 17-14.

Figure 17-14. Controls for the message-sending sample


Now add the following code to the form's class template:

 ' ----- Send a message to another computer. Process.Start("net.exe", _    "send " & TargetComputer.Text & _    " """ & MessageText.Text & """") 

The message you send appears in a message box on the other computer, similar to Figure 17-15.

Figure 17-15. A message received by the other computer


Both the sending and the receiving computer(s) must have the Messenger service running, or the message won't be sent. To enable this service under Windows XP, try the following steps:

  1. Click Start Control Panel, and open the Administrative Tools panel.

  2. Locate Messenger, and double-click its icon to open the Messenger Properties window.

  3. Set the Startup Type to Automatic, and click the Start button.

  4. Click the OK button, and close all open Control Panel windows.

This starts the Messenger service and causes it to restart each time Windows starts.




Visual Basic 2005 Cookbook(c) Solutions for VB 2005 Programmers
Visual Basic 2005 Cookbook: Solutions for VB 2005 Programmers (Cookbooks (OReilly))
ISBN: 0596101775
EAN: 2147483647
Year: 2006
Pages: 400

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net