#150029 - 2005-10-18 02:11 AM
Re: Best way to detect the logged-in user.
|
sixdoubleo
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
   
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 ....
|
|
Top
|
|
|
|
#150032 - 2005-10-18 01:15 PM
Re: Best way to detect the logged-in user.
|
Radimus
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
|
|
Top
|
|
|
|
#150034 - 2005-10-18 01:53 PM
Re: Best way to detect the logged-in user.
|
Richard H.
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
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
   
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
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?
|
|
Top
|
|
|
|
#150038 - 2005-10-20 12:00 AM
Re: Best way to detect the logged-in user.
|
NTDOC
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
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
1 registered
(mole)
and 759 anonymous users online.
|
|
|