Community discussions

MikroTik App
 
User avatar
Lucifer90
just joined
Topic Author
Posts: 3
Joined: Thu Nov 05, 2009 10:07 am

UserName of user logged on a device

Thu Apr 08, 2010 5:27 pm

Hello is there a possibility to have the user logged on a device displayed on the device on the map ?
I now you can add item: on Main "Setting", "Map" Tab, "Label" section to make it on the device
... but what add and where to get the user logged on the computer ?
thanks
 
jburns
just joined
Posts: 1
Joined: Wed Apr 28, 2010 5:19 pm

Re: UserName of user logged on a device

Wed Apr 28, 2010 5:21 pm

I would also like to know this. From what I've been able to find so far there isn't a way to do it via SNMP. Is it possible for the dude to work with LDAP to retrieve the username?
 
keith
Frequent Visitor
Frequent Visitor
Posts: 52
Joined: Thu May 24, 2007 12:30 am

Re: UserName of user logged on a device

Tue May 11, 2010 2:51 am

I don't think that it is exactly what you are looking for but i wrote(copied) a vb script that pulls the logged in user and displays it. I run it as a tool though. I can't figure out how to get it to display on the map. If you are interested i could post the code
 
User avatar
gsandul
Member Candidate
Member Candidate
Posts: 154
Joined: Mon Oct 19, 2009 1:42 pm

Re: UserName of user logged on a device

Tue May 11, 2010 8:35 am

keith, please, post the code, I'll try to make function to display the code result on a map.
 
keith
Frequent Visitor
Frequent Visitor
Posts: 52
Joined: Thu May 24, 2007 12:30 am

Re: UserName of user logged on a device

Thu May 13, 2010 2:00 am

Ok I have two. They are just vbs files. I attached the files also. They use wmi instead of snmp so i cant figure out how to put them in the labels

This one just finds out who is logged on.

'WhoLogonInput.vbs
' Sample VBScript to discover which user is logged on
' Author Guy Thomas and John Eck
' Version 2.5 - December 2005
' -------------------------------------------------------'
Option Explicit
Dim objWMIService, objComputer, colComputer
Dim strLogonUser, strLogonUser1, strComputer

strComputer = "."
strComputer = wscript.arguments(0)

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")

For Each objComputer in colComputer
If not objComputer.UserName = "" Then
strLogonUser = Split(objComputer.UserName,"\")
strLogonUser(1) = UCase(Left(strLogonUser(1),1))& Trim(Mid(strLogonUser(1),2,20))
Wscript.Echo strLogonUser(1) & " is logged on at " & strComputer
Else
Wscript.Echo "No one is currently logged on at " & strComputer
End If
Next

' End of Sample Logged on VBScript


This one gives additional info

If WScript.Arguments.Count = 1 Then
strComputer = WScript.Arguments.Item(0)
Else
strComputer = InputBox("Enter Computer Name")
End If
'
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")

'**********************Get Operating System *******************************************************************

Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_OperatingSystem",,48)
For Each objItem in colItems
os = "-----------------------------------" & vbCrLf & "PrimaryOS: " & objItem.Caption & vbCrLf & "-----------------------------------"
Next

'**********************Get Cpu Info*******************************************************************

Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_Processor",,48)
For Each objItem in colItems
if instr(os,"2000") < 1 then cores = objitem.NumberOfCores
cpu = "-----------------------------------" & vbCrLf & "CPU Name: " & objItem.Name & vbCrLf & "Cores = " & Cores & _
" Clock Speed = " & objitem.CurrentClockSpeed & vbCrLf & "-----------------------------------"
Next

'**********************Get Number and size of memory chips *******************************************************************

Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_PhysicalMemory",,48)
For Each objItem in colItems
dimmnum = dimmnum +1
dimmsize= cdbl(objitem.capacity)

if dimmsize > 1000000000 then
mem= mem & "-----------------------------------" & vbCrLf & "Dimm"& dimmnum &" Size: " & FormatNumber(dimmsize / 1000000000,2) & " GB" & vbCrLf & "-----------------------------------"
Else
mem= mem & "-----------------------------------" & vbCrLf & "Dimm"& dimmnum &" Size: " & FormatNumber(dimmsize / 1000000,2) & " MB" & vbCrLf & "-----------------------------------"
End if
Next

'**********************Get Model, Hostname, Logged in User, Total Memory *******************************************************************

Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_ComputerSystem",,48)
For Each objItem in colItems
model = "-----------------------------------" & vbCrLf & "Model: " & objItem.Model & vbCrLf & "-----------------------------------"
name = "-----------------------------------" & vbCrLf & "Hostname: " & objItem.name & vbCrLf & "-----------------------------------"

if ("-" & objitem.UserName & "-") = "--" then
username=" Nobody"
Else
username = objitem.UserName
end if
user = "-----------------------------------" & vbCrLf & "Logged In user:" & UserName & ":" & vbCrLf & "-----------------------------------"

dimmsize= cdbl(objitem.TotalPhysicalMemory)
if dimmsize > 1000000000 then
mem= mem & "-----------------------------------" & vbCrLf & "Total Memory: "& FormatNumber(dimmsize/1000000000,2) & " GB " & "(" & FormatNumber(dimmsize,0) & " Bytes)" & vbCrLf & "-----------------------------------"
Else
mem= mem & "-----------------------------------" & vbCrLf & "Total Memory:" & FormatNumber(dimmsize/10000,2) & " GB " & "(" & FormatNumber(dimmsize,0) & " Bytes)" & vbCrLf & "-----------------------------------"
End if

Next

'**********************Get Hard Drive Information *******************************************************************

Set colDisks = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk Where MediaType = '12'")
For Each objDisk in colDisks
drivespace = drivespace & "-----------------------------------" & vbCrLf & objdisk.deviceid & " " & int(objdisk.size/ 1000000000) & " GB total " & _
int(objDisk.FreeSpace/ 1000000000) & " GB free" & vbCrLf & "-----------------------------------"
Next



wscript.echo user & name & os & Model & totmem & mem & cpu & drivespace
 
User avatar
gsandul
Member Candidate
Member Candidate
Posts: 154
Joined: Mon Oct 19, 2009 1:42 pm

Re: UserName of user logged on a device

Thu May 13, 2010 1:53 pm

Hello.
keith, tnx for script.
The solution for this question is in "Probe Thread"

http://forum.mikrotik.com/viewtopic.php ... 43#p208043
 
keith
Frequent Visitor
Frequent Visitor
Posts: 52
Joined: Thu May 24, 2007 12:30 am

Re: UserName of user logged on a device

Thu May 13, 2010 8:53 pm

Thanks for the solution. Your explanation is excellent. I have wanted to do this for a long time but had no idea how to do it.
 
keith
Frequent Visitor
Frequent Visitor
Posts: 52
Joined: Thu May 24, 2007 12:30 am

Re: UserName of user logged on a device

Fri May 14, 2010 10:52 pm

Ok i tried this but i skipped hte user_pass function because i am on LAN and those are the only ones i want to access. When i create the Logged_User function i get a parse failed error. Any idea what that means. Here is the code i put in the function

array_element(execute("cscript.exe", concatenate("//NOLOGO c:\ra\whoison.vbs"),"c:\windows\system32\",1)

Thanks
 
keith
Frequent Visitor
Frequent Visitor
Posts: 52
Joined: Thu May 24, 2007 12:30 am

Re: UserName of user logged on a device

Fri May 14, 2010 11:12 pm

Never mind, I copied and paster your code and it modified it and it worked. Must have been missing a comma, quotes or parenthesis somewhere. Thanks again

Who is online

Users browsing this forum: No registered users and 20 guests