?
Solved

WMI:Get current Logged on User(Domain User Account)

Posted on 2004-11-15
12
Medium Priority
?
7,127 Views
Last Modified: 2008-01-09
Hi,

I need to get the current logged on user using WMI.

I tried using Win32_ComputerSystem but that gives the username only if the logged in user is using a local account.

I need to know the username even if the user is using a domain account.

Pls help.

Note:I just came across the Win32_NetworkLoginProfile class which contains some relevant information.Can anyone help?
0
Comment
Question by:ankuratvb
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12582541
have you tried just using    environment.username
0
 
LVL 9

Author Comment

by:ankuratvb
ID: 12582575
Hi RonaldBiemans,

I need the current logged on username of a remote computer that i'll connect to using WMI.

I guess environment.username would give me the username of the local system.
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12582664
yes environment.username just get the local system

have you tried using the networkconnection of WMI (Win32_NetworkConnection)

this has a username property aswell
0
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
LVL 9

Author Comment

by:ankuratvb
ID: 12589643
Hi Mikal613,

Thanx for the link but it doesnt have the solution,the problem is the same but
the solution wasnt attained.
0
 
LVL 18

Accepted Solution

by:
armoghan earned 1500 total points
ID: 12614850
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12890270
User has not tested/commented on my Comment.
Its a post on how to get the Current User using Win32_Process

0
 
LVL 9

Author Comment

by:ankuratvb
ID: 12892701
Yes,its true.

I havent been able to test out the method provided in the link. i was out for a while

I guess it'd be fair to award the points to armoghan with grade 'B'.
0
 

Expert Comment

by:jfluhmann
ID: 13538933
I searched and searched for a solution to the same problem.  I use Perl for everything, so I was looking for a Perl solution.  I came across this posting and several like it.  After adapting a VB script, I just wanted to throw this out as a Perl solution to the problem.  I understand that points have been awarded, yada, yada, yada.  I don't care about points or credit.

#!perl
# Adapted from -
#  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/wmi_tasks__accounts_and_domains.asp

use strict;
use Win32::OLE 'in';
$Win32::OLE::Warn = 3;

my $strComputer = shift || '.';
my $objWMIService = Win32::OLE->GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\" .
    $strComputer . "\\root\\cimv2");
my $colComputer = $objWMIService->ExecQuery("Select * from Win32_ComputerSystem");
 
foreach my $objComputer (in $colComputer) {
    print ($objComputer->{UserName} || 'no user logged on'),"\n";
}
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month14 days, 1 hour left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question