Page 1 of 1

UserName of user logged on a device

Posted: Thu Apr 08, 2010 5:27 pm
by Lucifer90
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

Re: UserName of user logged on a device

Posted: Wed Apr 28, 2010 5:21 pm
by jburns
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?

Re: UserName of user logged on a device

Posted: Tue May 11, 2010 2:51 am
by keith
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

Re: UserName of user logged on a device

Posted: Tue May 11, 2010 8:35 am
by gsandul
keith, please, post the code, I'll try to make function to display the code result on a map.

Re: UserName of user logged on a device

Posted: Thu May 13, 2010 2:00 am
by keith
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

Re: UserName of user logged on a device

Posted: Thu May 13, 2010 1:53 pm
by gsandul
Hello.
keith, tnx for script.
The solution for this question is in "Probe Thread"

http://forum.mikrotik.com/viewtopic.php ... 43#p208043

Re: UserName of user logged on a device

Posted: Thu May 13, 2010 8:53 pm
by keith
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.

Re: UserName of user logged on a device

Posted: Fri May 14, 2010 10:52 pm
by keith
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

Re: UserName of user logged on a device

Posted: Fri May 14, 2010 11:12 pm
by keith
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