"John Puopolo" <jo**********@f astsearch.com.n ospam> wrote in message
news:u4******** ******@TK2MSFTN GP10.phx.gbl...
All:
I am writing a "net send" like application. The application runs on each
person's PC, waiting for messages.
Let's suppose "Joe" is logged in to 2 PCs, A and B. I would like to enter
acommand (from my PC) like: sendto joe hello
I would then like a window to pop up on PC A and PC B with "hello." In
order to do this, I need a way to determine all of the computers where Joe
is logged in as user.
the psuedocode is something like:
foreach (node on the network) {
if (user logged in is target_user) {
send target_user the_message
}
}
Is this possible?
Yes, using System.Manageme nt and WMI.
Note that this requires access privileges to the remote systems WMI service
to run.
string machineName = "remote";
ConnectionOptio ns options = new ConnectionOptio ns();
options.Usernam e = "someuser"; //user (domain or local) with sufficient
privileges to access the remote system through WMI
options.Passwor d = "secret";
ManagementScope s = new ManagementScope ("\\\\" + machineName +
"\\root\\cimv2" , options);
ManagementPath p = new ManagementPath( "Win32_Computer System.Name='" +
machineName +"'");
using(Managemen tObject cs = new ManagementObjec t (s, p, null ))
{
cs.Get();
Console.WriteLi ne(cs["UserName"]);
}
Willy.