3 Replies Latest reply on Aug 8, 2011 5:41 AM by AndyCoates

    Application Performance Monitor

    kristian_tomol13

      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)?

        • Re: Application Performance Monitor
          AndyCoates

          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)?

            • Re: Application Performance Monitor
              kristian_tomol13

              Yes, I just want to see the numbers of users currently logged on that server.

                • Re: Application Performance Monitor
                  AndyCoates

                  Based on this article: http://stackoverflow.com/questions/898757/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: " & Message
                  End If