grimmlock Posted September 5, 2013 Share Posted September 5, 2013 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. expandcollapse popup #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 Thanks Grimm Link to comment Share on other sites More sharing options...
MilesAhead Posted September 5, 2013 Share Posted September 5, 2013 You can handle the WM_QUERYENDSESSION message http://msdn.microsoft.com/en-us/library/windows/desktop/aa376890(v=vs.85).aspx/html My Freeware Page Link to comment Share on other sites More sharing options...
Valuater Posted September 5, 2013 Share Posted September 5, 2013 here are different approaches to this... but I would look at this script that includes the info MilesAhead stated. 8) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now