Page 2 of 2 <12
Topic Options
#150029 - 2005-10-18 02:11 AM Re: Best way to detect the logged-in user.
sixdoubleo Offline
Starting to like KiXtart

Registered: 2004-02-06
Posts: 118
Loc: California, US
Quote:

also...

Quote:

UserName
Data type: string
Access type: Read-only

Name of a user that is logged on currently. This property must have a value. In a terminal services session, UserName returns the name of the user that is logged on to the console—not the user logged on during the terminal service session.








I'm confused now. How am I supposed to use that?

Top
#150030 - 2005-10-18 02:22 AM Re: Best way to detect the logged-in user.
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
Quote:

Quote:

what value are you giving $computer




$computer = @WKSTA




I'm a dumbass...

$UserNames = WMIQuery('UserName','Win32_ComputerSystem',$Computer)
for each ....
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#150031 - 2005-10-18 06:51 AM Re: Best way to detect the logged-in user.
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
Rad,

I know that works for CURRENTLY LOGGED ON USER at the console, but have you tested it against a Terminal Server to see if it lists all the sessions?

He wants ALL users, not the one on the console. I'm not sure if WMI has something for that or not. He might have to go with one of the external methods described already if not.

Top
#150032 - 2005-10-18 01:15 PM Re: Best way to detect the logged-in user.
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
He said workstation, not terminal server

I'm pretty sure it would do that as well
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#150033 - 2005-10-18 01:38 PM Re: Best way to detect the logged-in user.
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
He wants both.....

Quote:


....
I seem to remember some command (maybe in the resource kit) which will list all the terminal and console login sessions. I could parse this I thought.



_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#150034 - 2005-10-18 01:53 PM Re: Best way to detect the logged-in user.
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quote:

tasklist /FI would work, but I dont get the user name on that.




You need the /V flag.

Here is an example using tasklist.exe:

Code:
Break ON
$=SetOption("WrapAtEOL","ON")
For Each $sLine in WshPipe('tasklist /v /FI "imagename eq explorer.exe" /fo CSV /nh')
$aResult=Split($sLine,'","')
If UBound($aResult)>6 "Logged in user='"+$aResult[6]+"'"+@CRLF EndIf
Next

Function WshPipe($ShellCMD)
Dim $oExec, $Output
$oExec = CreateObject("WScript.Shell").Exec($ShellCMD)
If Not VarType($oExec)=9 $WshPipe="WScript.Shell Exec Unsupported" Exit 10 EndIf
$Output = $oExec.StdOut.ReadAll + $oExec.StdErr.ReadAll
$WshPipe=Split(Join(Split($Output,CHR(13)),''),CHR(10))
Exit($oExec.ExitCode)
EndFunction


Top
#150035 - 2005-10-19 12:04 AM Re: Best way to detect the logged-in user.
sixdoubleo Offline
Starting to like KiXtart

Registered: 2004-02-06
Posts: 118
Loc: California, US
Quote:

He wants both.....

Quote:


....
I seem to remember some command (maybe in the resource kit) which will list all the terminal and console login sessions. I could parse this I thought.








I'm actually looking for the console user. I was just saying that I remember some type of cmd line utility from my TS days that was sort of like a unix "who" command.

Anyway, using the WMIQuery example I'm currently grabbing what I need. Thanks for all of the suggestions!

Top
#150036 - 2005-10-19 01:10 AM Re: Best way to detect the logged-in user.
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
Quote:

He said workstation, not terminal server

I'm pretty sure it would do that as well




Well it will ONLY return the ACCOUNT currently logged on at the console. It will NOT return any other accounts on any other type of server.

Yes it will return the ACCOUNT from either Workstation or Server, but only the CONSOLE 0 account, not others.

 

Top
#150037 - 2005-10-19 08:11 PM Re: Best way to detect the logged-in user.
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
What is wrong with the silver platter coded solution I presented near the top of the thread? Has anyone tried it?
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#150038 - 2005-10-20 12:00 AM Re: Best way to detect the logged-in user.
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
Howard, long story short - it looks like all he was really wanting was the user logged onto the console which WMI does provide.

I did say though that he might have to use another method if he wants the sessions.

Quote:

He might have to go with one of the external methods described already if not.




 

Top
Page 2 of 2 <12


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 595 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.099 seconds in which 0.063 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org