Hi All,
I would like to ask if it is possible for APM to gather information on users that are currently logged in on a particular server (for example, Windows Server 2003)?
Are you just wanting the number of users logged in so that you can alert on a certain threshold of users? Also, should this include remote logins (terminal services etc)?
Yes, I just want to see the numbers of users currently logged on that server.
Based on this article: stackoverflow.com/.../vb-using-wmi-get-logged-in-users
Make an APM monitor using Windows Script Monitor and paste the code below in. As the argument you could use ${IP} to apply to the server the test is placed on, otherwise the argument is the target server to run on (based on your credentials).
''Pass target server IP to script'strComputer = wScript.Arguments(0)Set objWMI = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" _ & strComputer & "\root\cimv2") Set colSessions = objWMI.ExecQuery _ ("Select * from Win32_LogonSession Where LogonType = 10") If colSessions.Count = 0 Then Wscript.Echo "Statistic: 0" Wscript.Echo "Message: No users logged in"Else LoggedIn = 0 For Each objSession in colSessions Set colList = objWMI.ExecQuery("Associators of " _ & "{Win32_LogonSession.LogonId=" & objSession.LogonId & "} " _ & "Where AssocClass=Win32_LoggedOnUser Role=Dependent" ) For Each objItem in colList LoggedIn = LoggedIn + 1 Message = Message & objItem.Name & ", " Next Next Wscript.Echo "Statistic: " & LoggedIn Wscript.Echo "Message: " & MessageEnd If