473,395 Members | 1,941 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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
}
}
************************************************** ************************************************** **

Jun 6 '07 #1
2 14149
"Heike Pertzel" <HP****@DATA5.dewrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
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
}
}
************************************************** ************************************************** **

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

Willy.

Jun 7 '07 #2
Hallo Willy,

thank you for your answer.

I've got a solution now that works in some cases. I'm testing along. If I
need your help again I'll start a new question.

Heike Pertzel

"Willy Denoyette [MVP]" <wi*************@telenet.beschrieb im Newsbeitrag
news:uT**************@TK2MSFTNGP03.phx.gbl...
"Heike Pertzel" <HP****@DATA5.dewrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>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
}
}
************************************************* ************************************************** ***


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

Willy.

Jun 8 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Lamont | last post by:
VB.NET Can anyone tell me how I can get the Drive Space information from a remote computer on the same domain and physical network? Primarily I need the Total disk space and space used or free...
1
by: Yaniv M | last post by:
Hi, How can I get information of specific file in remote computer? I want to get file's status in other computer, this file belongs to shared directory, I want to get the file size, existanse of...
1
by: Uzi Baruch | last post by:
Hi! I need to get file information from a remote computer, the thing is, i need to use different credentials to get that information. My question is: how the add the credentials to my...
1
by: Chidvilas | last post by:
// Get all processes running on the remote computer. Process remoteAll = Process.GetProcesses("XYZ"); when I am exectuing the above code, it is giving excetpion saying "Couldn't get process...
1
by: schaf | last post by:
Hi all! I'm still trying to start/stop a service on a remote computer. (I promiss that's the last new post because of this problem from my side) My situation: I've an application running under...
0
by: Zebadunc | last post by:
I have a vb.net form that lists the shared printers in from a remote computer in a checklist box giving the shareName as the value for the user to select. I want to use the print server name and...
1
by: gabriel.altay | last post by:
hello everyone, Im trying to write some python code that will return information (file size, last modified ...) about files on a remote computer that I have 'no password' ssh access to. Ive...
3
by: Tracid83 | last post by:
Hi, I would like to enumerate user from remote computer connected to network. I don't use wmi service because all service necessary don't start. I just know IP address and Netbios name. Do you...
0
by: snagrao | last post by:
Sir, please help me in Visualbasic 6 . my requirement is , i stored photos at remote computer and write code in VB forms to access it. if computer at remote is connected to clint by goinmg from...
4
by: wickedweapon | last post by:
Hi, I'm trying to access a remote computer and view its running processes thorugh WMI by using a script on my system but i keep getting "RPC server unavailable" error.I have changed the COM...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.