Discovering Whose Logged On To Remote System?

  • Thread starter Thread starter John Puopolo
  • Start date Start date
J

John Puopolo

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?

Thanks,
John
 
John Puopolo said:
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.Management and WMI.
Note that this requires access privileges to the remote systems WMI service
to run.

string machineName = "remote";
ConnectionOptions options = new ConnectionOptions();
options.Username = "someuser"; //user (domain or local) with sufficient
privileges to access the remote system through WMI
options.Password = "secret";
ManagementScope s = new ManagementScope("\\\\" + machineName +
"\\root\\cimv2", options);
ManagementPath p = new ManagementPath("Win32_ComputerSystem.Name='" +
machineName +"'");
using(ManagementObject cs = new ManagementObject (s, p, null ))
{
cs.Get();
Console.WriteLine(cs["UserName"]);
}

Willy.
 
Back
Top