#NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Change2CUI=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** $strHelp = "UNKOWN: check_users.exe (v 1.0) - See who last logged on and number of users currently logged on" & _ chr(10) & chr(10) & "Usage: check_users.exe [-l] [-u username] [-n] [-w warning] [-c critical]" & chr(10) & _ " -l Show username of last user logged in" & chr(10) & " -u (optional) Used with -l to define user that should have logged in." & _ chr(10) & " If defined, status will be critical if user was not last logged in." & chr(10) & _ " If not defined, status will always be ok." & chr(10) & " -n Show number of users logged in" & _ chr(10) & " -w (optional) used with -n to return warning status if number of logged" & chr(10) & _ " in users is not within range" & chr(10) & " -c (optional) used with -n to return critical status if number of logged" & _ chr(10) & " in users is not within range" & _ chr(10) & chr(10) & "When using warning/critical returns with the -n option, both a warning and critical must be defined." If $CmdLine[0] = 0 Then ConsoleWrite($strHelp) Else Switch $CmdLine[1] Case "-l" Switch @OSVersion Case "WIN_2008", "WIN_2008R2" If @OSArch = "X86" Then $strLastLoggedOnUser = RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI", "LastLoggedOnUser") Else $strLastLoggedOnUser = RegRead("HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI", "LastLoggedOnUser") EndIf Case Else $strLastLoggedOnUser = RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon", "DefaultDomainName") & "\" & RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon", "DefaultUserName") EndSwitch If $CmdLine[0] = 3 Then If $CmdLine[2] = "-u" Then If StringLower($strLastLoggedOnUser) <> StringLower($CmdLine[3]) Then ConsoleWrite("CRITICAL: " & $strLastLoggedOnUser & " is the last logged in user") Exit(2) EndIf EndIf EndIf ConsoleWrite("OK: " & $strLastLoggedOnUser & " is the last logged in user") Exit(0) Case "-n" Dim $arrLoggedOnUsers[1][1] $arrLoggedOnUsers = ProcessList("explorer.exe") $numLoggedOnUsers = $arrLoggedOnUsers[0][0] If $CmdLine[0] = 5 Then Switch $CmdLine[2] Case "-w" $strWarning = $CmdLine[3] Case "-c" $strCritical = $CmdLine[3] Case Else ConsoleWrite($strHelp) Exit(3) EndSwitch Switch $CmdLine[4] Case "-w" $strWarning = $CmdLine[5] Case "-c" $strCritical = $CmdLine[5] Case Else ConsoleWrite($strHelp) Exit(3) EndSwitch If StringInStr($strWarning, ":") <> 0 Then If StringInStr($strWarning, ":") = StringLen($strWarning) Then $numWarning = StringLeft($strWarning, StringLen($strWarning) - 1) EndIf Else $numWarning = $strWarning EndIf If StringInStr($strCritical, ":") <> 0 Then If StringInStr($strCritical, ":") = StringLen($strCritical) Then $numCritical = StringLeft($strCritical, StringLen($strCritical) - 1) If $numLoggedOnUsers < $numCritical Then ConsoleWrite("CRITICAL: " & $numLoggedOnUsers & " users are logged in |'users'=" & $numLoggedOnUsers & ";" & $numWarning & ";" & $numCritical) Exit(2) Else ConsoleWrite("OK: " & $numLoggedOnUsers & " users are logged in |'users'=" & $numLoggedOnUsers & ";" & $numWarning & ";" & $numCritical) Exit(0) EndIf EndIf Else $numCritical = $strCritical If $numLoggedOnUsers > $numCritical Then ConsoleWrite("CRITICAL: " & $numLoggedOnUsers & " users are logged in |'users'=" & $numLoggedOnUsers & ";" & $numWarning & ";" & $numCritical) Exit(2) Else ConsoleWrite("OK: " & $numLoggedOnUsers & " users are logged in |'users'=" & $numLoggedOnUsers & ";" & $numWarning & ";" & $numCritical) Exit(0) EndIf EndIf If StringInStr($strWarning, ":") <> 0 Then If StringInStr($strWarning, ":") = StringLen($strWarning) Then $numWarning = StringLeft($strWarning, StringLen($strWarning) - 1) If $numLoggedOnUsers < $numWarning Then ConsoleWrite("WARNING: " & $numLoggedOnUsers & " users are logged in |'users'=" & $numLoggedOnUsers & ";" & $numWarning & ";" & $numCritical) Exit(1) Else ConsoleWrite("OK: " & $numLoggedOnUsers & " users are logged in |'users'=" & $numLoggedOnUsers & ";" & $numWarning & ";" & $numCritical) Exit(0) EndIf EndIf Else $numWarning = $strWarning If $numLoggedOnUsers > $numWarning Then ConsoleWrite("WARNING: " & $numLoggedOnUsers & " users are logged in |'users'=" & $numLoggedOnUsers & ";" & $numWarning & ";" & $numCritical) Exit(1) Else ConsoleWrite("OK: " & $numLoggedOnUsers & " users are logged in |'users'=" & $numLoggedOnUsers & ";" & $numWarning & ";" & $numCritical) Exit(0) EndIf EndIf Else ConsoleWrite("OK: " & $numLoggedOnUsers & " users are logged in |'users'=" & $numLoggedOnUsers) Exit(0) EndIf Case Else ConsoleWrite($strHelp) Exit(3) EndSwitch EndIf