Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

C# Programming

Getting the name of user on remote computer


Hallo NG!

I would like to get the name of the user logged on on a another computer.
I've written the following code which gives me the LogonId of  this user.
But getting with this Id the name of the user doesn't work.

I would appreciate every hint or help!

Regards
Heike Pertzel

*************************************************************************** ***************************
using System.Management;

string UserLogonId ;
string Username;
ManagementScope msc = new ManagementScope("\\\\" + IP of the OTHER computer
+ "\\root\\cimv2");
string queryString = "select LogonId from win32_logonsession where logontype
= 2";
query = new ManagementObjectSearcher(msc, new SelectQuery(queryString));
foreach( ManagementObject mo in query.Get())
{
    UserLogonId = mo["LogonId"].ToString();  // WORKS !!!!!!
    RelatedObjectQuery relatedQuery = new RelatedObjectQuery("associators of
{Win32_LogonSession.LogonId='" + mo["LogonId"]+ "'}WHERE AssocClass =
Win32_LoggedOnUser");
    ManagementObjectSearcher searcher = new ManagementObjectSearcher(msc,
relatedQuery);
    foreach (ManagementObject mob in searcher.Get())
    {
        Username = mob["Caption"] + " " + mob["Domain"] + " " + mob["Name"];
// DOESN'T WORK !!!!!!! they are always empty strings
    }

}

*************************************************************************** ***************************
"Heike Pertzel" <HPN@DATA5.de> wrote in message

news:%235lHwvAqHHA.4608@TK2MSFTNGP02.phx.gbl...

This should work, provided the remote system runs XP or higher.

Willy.

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc