DigDeep Posted June 27, 2017 Posted June 27, 2017 I have the below function set for log files inside my code using it at multiple locations. I wanted to continue the log file after Step 6 when the computer restarts. Local $log = 0 Func LogFilePath() If $log = 0 Then $GetLog = "C:\Temp\Test\Test.log" _FileCreate($GetLog) If FileExists($GetLog) Then ; Log Line 1 ; Log Line 2 ; Log Line 3 ; Log line 4 EndIf $log = 1 EndIf EndFunc ; Write some functions here... ; Step 1 LogFilePath() _FileWriteLog($GetLog, "Line 5") ; Step 2 LogFilePath() _FileWriteLog($GetLog, "Line 6") ; Reboot ; Want to continue the log lines after line 6.
water Posted June 27, 2017 Posted June 27, 2017 You need to save the status of your script in a location that survives the reboot (Ini-file, registry ...). First step in your script is then to check and reset this state. You then call your functions depending on the state. Xandy 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Subz Posted June 27, 2017 Posted June 27, 2017 I you use FileOpen with mode = 1 then it will always append to end of your file something like: expandcollapse popup#include <File.au3> OnAutoItExitRegister("_LogClose") Global $hLogFile, $sLogFile, $bLog = False LogFilePath() Func LogFilePath() If $bLog = False Then $sLogFile = EnvGet("SystemDrive") & "\Temp\Test\Test.log" $hLogFile = FileOpen($sLogFile, 9) ;~ Create Folder/File and append to end of file if it already exists If $hLogFile > -1 Then _FileWriteLog($sLogFile, "Line 1") _FileWriteLog($sLogFile, "Line 2") _FileWriteLog($sLogFile, "Line 3") _FileWriteLog($sLogFile, "Line 4") $bLog = True EndIf EndIf EndFunc ; Step 1 Function ;~ Check if Step 1 has been completed If FileExists(@ProgramFilesDir & "\Filepath1\Filename1.exe") = 0 Then ;~ Run Step 1 Installer here RunWait('MsiExec.exe /i "' & @ScriptDir & '\FileName1.msi" /qb /norestart') If $bLog = True Then _FileWriteLog($sLogFile, "Step 1 Completed") EndIf ; Step 2 Function If RegRead("HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\{Guid}", "DisplayName") = "" Then ;~ Run Step 2 Installer here RunWait('MsiExec.exe /i "' & @ScriptDir & '\FileName2.msi" /qb /norestart') If $bLog = True Then _FileWriteLog($sLogFile, "Step 2 Completed") EndIf ; Reboot ; Step 3 Function ; Want to continue the log lines after line 6. Func _LogClose() FileClose($hLogFile) Exit EndFunc SkysLastChance 1
water Posted June 28, 2017 Posted June 28, 2017 Example: expandcollapse popup#include <MsgBoxConstants.au3> Global $iState = Number(IniRead(@ScriptDir & "\State.ini", "State", "State", 0)) ; Step 1 If $iState < 1 Then $iState += 1 MsgBox(0, "", "Executing Step " & $iState) IniWrite(@ScriptDir & "\State.ini", "State", "State", $iState) If MsgBox($MB_YESNO, "Step " & $iState, "Should I exit the script here?") = 6 Then Exit EndIf ; Step 2 If $iState < 2 Then $iState += 1 MsgBox(0, "", "Executing Step " & $iState) IniWrite(@ScriptDir & "\State.ini", "State", "State", $iState) If MsgBox($MB_YESNO, "Step " & $iState, "Should I exit the script here?") = 6 Then Exit EndIf ; Step 3 If $iState < 3 Then $iState += 1 MsgBox(0, "", "Executing Step " & $iState) IniWrite(@ScriptDir & "\State.ini", "State", "State", $iState) If MsgBox($MB_YESNO, "Step " & $iState, "Should I exit the script here?") = 6 Then Exit EndIf ; Step 4 If $iState < 4 Then $iState += 1 MsgBox(0, "", "Executing Step " & $iState) IniWrite(@ScriptDir & "\State.ini", "State", "State", $iState) If MsgBox($MB_YESNO, "Step " & $iState, "Should I exit the script here?") = 6 Then Exit EndIf ; Step 5 If $iState < 5 Then $iState += 1 MsgBox(0, "", "Executing Step " & $iState) IniWrite(@ScriptDir & "\State.ini", "State", "State", $iState) If MsgBox($MB_YESNO, "Step " & $iState, "Should I exit the script here?") = 6 Then Exit EndIf ; Step 6 If $iState < 6 Then $iState += 1 MsgBox(0, "", "Executing Step " & $iState) IniWrite(@ScriptDir & "\State.ini", "State", "State", $iState) If MsgBox($MB_YESNO, "Step " & $iState, "Should I exit the script here?") = 6 Then Exit EndIf My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
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