Search the Community
Showing results for tags 'logout'.
-
I created this script but would like to help fine tuning it. My goal is to add this to a existing GUI script, and have this function only run if a user logs out of the computer without filling in the GUI form. Any ideas or help would be greatly appreciated. #include <File.au3> #include <Array.au3> Local $aLines, $iCount = 0 local $hDate = @YEAR & '-' & @MON & '-' & @MDAY local $hfile=FileOpen("\\192.168.26.17\Logs\testlog.txt", 1) OnAutoItExitRegister("MyTestFunc") Sleep(2000) Func MyTestFunc() local $sUsername = @UserName ; User Name Local $sComputername = @ComputerName ; Computer Name $sText1 = "Username = " & $sUsername & @CRLF ; The & character concentrates (joins) two values together. $sText2 = "Computer Name = " & $sComputername & @CRLF ; The &= adds to the variable. The same as doing $var = $var & "extra stuff" _FileReadToArray("\\192.168.26.17\Logs\testlog.txt", $aLines) If Not @error Then ; if the file exists look for the ID starting on the last line For $i = $aLines[0] To 1 Step -1 If StringLeft($aLines[$i], 2) == "id" Then ; get the ID number $iCount = Int(StringRegExpReplace($aLines[$i], "id(\d*):.*", "$1")) ExitLoop EndIf Next ; Check we found an ID If $i = 0 Then MsgBox(0, "Error", "No line id found") Exit EndIf EndIf FileWrite($hfile, _LineID() & '|' & $hDate & '|' & $sComputername & '|' & $sUsername & '|' &'logged off' & @CRLF) FileClose($hfile) EndFunc Func _LineID() $iCount += 1 Return "id" & StringFormat("%04i", $iCount) & ": " EndFunc ;==> LineID