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

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?
LVL 9
ankuratvbAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RonaldBiemansCommented:
have you tried just using    environment.username
0
ankuratvbAuthor Commented:
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
RonaldBiemansCommented:
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
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

ankuratvbAuthor Commented:
Hi Mikal613,

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
armoghanCommented:
User has not tested/commented on my Comment.
Its a post on how to get the Current User using Win32_Process

0
ankuratvbAuthor Commented:
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
jfluhmannCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.