Community discussions

MikroTik App
 
keith
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 52
Joined: Thu May 24, 2007 12:30 am

Get Currently logged in user

Thu May 24, 2007 8:47 pm

Is it possible to get the currently logged in user on a machine. I know that you can get it via wscriptwitht he following code:

Function QPO
On Error Resume next
strLookFor = "Kbyrum"
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = 'explorer.exe'")
For Each objProcess in colProcessList
objProcess.GetOwner strUserName, strUserDomain
'WScript.StdOut.Write strInput
Wscript.stdout.write strComputer &",Is logged into by "&strUserDomain & "\" & strUserName &","&time
if strUserName = strLookfor then
Wscript.echo strUserName & "is logged into " & strComputer
end if
Next
End Function
 
winkelman
Member Candidate
Member Candidate
Posts: 231
Joined: Wed Aug 16, 2006 5:00 pm
Location: Amsterdam, The Netherlands

Re: Get Currently logged in user

Fri May 25, 2007 12:56 pm

Did you perform a SNMP Walk and try to find the correct OID (if it exists)? That's usually the best way to search for specific SNMP info...
 
keith
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 52
Joined: Thu May 24, 2007 12:30 am

Re: Get Currently logged in user

Fri May 25, 2007 6:14 pm

Unfortunately I have no clue how to do snmp stuff. I have experimented with it in the dude but have had no success. Do you know of any good online tutorials on snmp?
 
winkelman
Member Candidate
Member Candidate
Posts: 231
Joined: Wed Aug 16, 2006 5:00 pm
Location: Amsterdam, The Netherlands

Re: Get Currently logged in user

Fri May 25, 2007 6:23 pm

You can start here: http://en.wikipedia.org/wiki/Snmp

Basically, if you Google on SNMP, you will find a ton of stuff. Just take a day (or two, or three... :-)) to learn and play and you'll get started...

Also: if you want to query Windows machines you'd first have to install the SNMP Agent. It's provided with Windows, but not installed by default. Go to Add/Remove Programs, Windows Components and look for in there. You may also have to go into Windows Services (after installation of the Agent) to configure the SNMP Agent a little there.
 
keith
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 52
Joined: Thu May 24, 2007 12:30 am

Re: Get Currently logged in user

Fri May 25, 2007 7:36 pm

I will squeeze that into my schedule. I did however get it to work using a vb script instead. I saved the script as WHoison.vbs and added it as a tool. The code is below for anyone who is interested

DIM strComputer
DIM strUsername

strComputer=WScript.Arguments.Item(0)


'-------------------------- GET USERNAME CURRENTLY LOGGED IN ------------------------------------------------------------

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem")
For Each objItem In colItems
strUsername = objItem.UserName
Next

wscript.echo strUsername & " is currently logged on to this computer"

wscript.quit
 
winkelman
Member Candidate
Member Candidate
Posts: 231
Joined: Wed Aug 16, 2006 5:00 pm
Location: Amsterdam, The Netherlands

Re: Get Currently logged in user

Tue May 29, 2007 10:38 am

I've checked and logged in user name(s) does not seem to be something query-able through SNMP. You can query for an array of users, but there's no way to find out which one(s) is/are logged in.

Of course, there are lot's of ways to expand on the default SNMP MIB...

Anyway, seems you did a good job creating the VB-script :).
 
keith
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 52
Joined: Thu May 24, 2007 12:30 am

Re: Get Currently logged in user

Thu May 31, 2007 1:46 am

Can't claim credit for that, all I did was copy from somebody else :)

Who is online

Users browsing this forum: No registered users and 12 guests