document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #NoTrayIcon
  2. #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
  3. #AutoIt3Wrapper_Change2CUI=y
  4. #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
  5. $strHelp = "UNKOWN: check_users.exe (v 1.0) - See who last logged on and number of users currently logged on" & _
  6.     chr(10) & chr(10) & "Usage: check_users.exe [-l] [-u username] [-n] [-w warning] [-c critical]" & chr(10) & _
  7.     "   -l   Show username of last user logged in" & chr(10) & "   -u   (optional) Used with -l to define user that should have logged in." & _
  8.     chr(10) & "        If defined, status will be critical if user was not last logged in." & chr(10) & _
  9.     "        If not defined, status will always be ok." & chr(10) & "   -n   Show number of users logged in" & _
  10.     chr(10) & "   -w   (optional) used with -n to return warning status if number of logged" & chr(10) & _
  11.     "        in users is not within range" & chr(10) & "   -c   (optional) used with -n to return critical status if number of logged" & _
  12.     chr(10) & "        in users is not within range" & _
  13.     chr(10) & chr(10) & "When using warning/critical returns with the -n option, both a warning and critical must be defined."
  14.  
  15. If $CmdLine[0] = 0 Then
  16.     ConsoleWrite($strHelp)
  17. Else
  18.     Switch $CmdLine[1]
  19.         Case "-l"
  20.             Switch @OSVersion
  21.                 Case "WIN_2008", "WIN_2008R2"
  22.                     If @OSArch = "X86" Then
  23.                         $strLastLoggedOnUser = RegRead("HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Authentication\\LogonUI", "LastLoggedOnUser")
  24.                     Else
  25.                         $strLastLoggedOnUser = RegRead("HKLM64\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Authentication\\LogonUI", "LastLoggedOnUser")
  26.                     EndIf
  27.                 Case Else
  28.                     $strLastLoggedOnUser = RegRead("HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\WinLogon", "DefaultDomainName") & "\\" & RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\WinLogon", "DefaultUserName")
  29.             EndSwitch
  30.             If $CmdLine[0] = 3 Then
  31.                 If $CmdLine[2] = "-u" Then
  32.                     If StringLower($strLastLoggedOnUser) <> StringLower($CmdLine[3]) Then
  33.                         ConsoleWrite("CRITICAL: " & $strLastLoggedOnUser & " is the last logged in user")
  34.                         Exit(2)
  35.                     EndIf
  36.                 EndIf
  37.             EndIf
  38.             ConsoleWrite("OK: " & $strLastLoggedOnUser & " is the last logged in user")
  39.             Exit(0)
  40.         Case "-n"
  41.             Dim $arrLoggedOnUsers[1][1]
  42.             $arrLoggedOnUsers = ProcessList("explorer.exe")
  43.             $numLoggedOnUsers = $arrLoggedOnUsers[0][0]
  44.             If $CmdLine[0] = 5 Then
  45.                 Switch $CmdLine[2]
  46.                     Case "-w"
  47.                         $strWarning = $CmdLine[3]
  48.                     Case "-c"
  49.                         $strCritical = $CmdLine[3]
  50.                     Case Else
  51.                         ConsoleWrite($strHelp)
  52.                         Exit(3)
  53.                 EndSwitch
  54.                 Switch $CmdLine[4]
  55.                     Case "-w"
  56.                         $strWarning = $CmdLine[5]
  57.                     Case "-c"
  58.                         $strCritical = $CmdLine[5]
  59.                     Case Else
  60.                         ConsoleWrite($strHelp)
  61.                         Exit(3)
  62.                 EndSwitch
  63.                 If StringInStr($strWarning, ":") <> 0 Then
  64.                     If StringInStr($strWarning, ":") = StringLen($strWarning) Then
  65.                         $numWarning = StringLeft($strWarning, StringLen($strWarning) - 1)
  66.                     EndIf
  67.                 Else
  68.                     $numWarning = $strWarning
  69.                 EndIf
  70.                 If StringInStr($strCritical, ":") <> 0 Then
  71.                     If StringInStr($strCritical, ":") = StringLen($strCritical) Then
  72.                         $numCritical = StringLeft($strCritical, StringLen($strCritical) - 1)
  73.                         If $numLoggedOnUsers < $numCritical Then
  74.                             ConsoleWrite("CRITICAL: " & $numLoggedOnUsers & " users are logged in |\'users\'=" & $numLoggedOnUsers & ";" & $numWarning & ";" & $numCritical)
  75.                             Exit(2)
  76.                         Else
  77.                             ConsoleWrite("OK: " & $numLoggedOnUsers & " users are logged in |\'users\'=" & $numLoggedOnUsers & ";" & $numWarning & ";" & $numCritical)
  78.                             Exit(0)
  79.                         EndIf
  80.                     EndIf
  81.                 Else
  82.                     $numCritical = $strCritical
  83.                     If $numLoggedOnUsers > $numCritical Then
  84.                         ConsoleWrite("CRITICAL: " & $numLoggedOnUsers & " users are logged in |\'users\'=" & $numLoggedOnUsers & ";" & $numWarning & ";" & $numCritical)
  85.                         Exit(2)
  86.                     Else
  87.                         ConsoleWrite("OK: " & $numLoggedOnUsers & " users are logged in |\'users\'=" & $numLoggedOnUsers & ";" & $numWarning & ";" & $numCritical)
  88.                         Exit(0)
  89.                     EndIf
  90.                 EndIf
  91.                 If StringInStr($strWarning, ":") <> 0 Then
  92.                     If StringInStr($strWarning, ":") = StringLen($strWarning) Then
  93.                         $numWarning = StringLeft($strWarning, StringLen($strWarning) - 1)
  94.                         If $numLoggedOnUsers < $numWarning Then
  95.                             ConsoleWrite("WARNING: " & $numLoggedOnUsers & " users are logged in |\'users\'=" & $numLoggedOnUsers & ";" & $numWarning & ";" & $numCritical)
  96.                             Exit(1)
  97.                         Else
  98.                             ConsoleWrite("OK: " & $numLoggedOnUsers & " users are logged in |\'users\'=" & $numLoggedOnUsers & ";" & $numWarning & ";" & $numCritical)
  99.                             Exit(0)
  100.                         EndIf
  101.                     EndIf
  102.                 Else
  103.                     $numWarning = $strWarning
  104.                     If $numLoggedOnUsers > $numWarning Then
  105.                         ConsoleWrite("WARNING: " & $numLoggedOnUsers & " users are logged in |\'users\'=" & $numLoggedOnUsers & ";" & $numWarning & ";" & $numCritical)
  106.                         Exit(1)
  107.                     Else
  108.                         ConsoleWrite("OK: " & $numLoggedOnUsers & " users are logged in |\'users\'=" & $numLoggedOnUsers & ";" & $numWarning & ";" & $numCritical)
  109.                         Exit(0)
  110.                     EndIf
  111.                 EndIf
  112.             Else
  113.                 ConsoleWrite("OK: " & $numLoggedOnUsers & " users are logged in |\'users\'=" & $numLoggedOnUsers)
  114.                 Exit(0)
  115.             EndIf
  116.         Case Else
  117.             ConsoleWrite($strHelp)
  118.             Exit(3)
  119.     EndSwitch
  120. EndIf
');