473,326 Members | 2,113 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,326 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 14137
"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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.