PantZ4 Posted September 2, 2006 Share Posted September 2, 2006 Could someone give a newbie( :"> ) a tip or two on creating and use log files? Like: When first time the program runs it creates a .log file and put a variable into the log file. Next time it is being runed it read the variable and set into the script... Thank you Link to comment Share on other sites More sharing options...
Azu Posted September 2, 2006 Share Posted September 2, 2006 Could someone give a newbie( :"> ) a tip or two on creating and use log files? Like:When first time the program runs it creates a .log file and put a variable into the log file.Next time it is being runed it read the variable and set into the script...Thank you Check out IniWrite and IniRead in the help file. I think that's what you are looking for. Link to comment Share on other sites More sharing options...
Valuater Posted September 2, 2006 Share Posted September 2, 2006 here is a login that uses two approaches, a GUI and Inputbox expandcollapse popup#include <GuiConstants.au3> Dim $user, $pass $inipath = @DesktopDir $user = IniRead($inipath & "\stoogelog.ini", "Login", "User", "Not Found") $pass = IniRead($inipath & "\stoogelog.ini", "Login", "Password", "Not Found") If $user = "Not Found" Or $pass = "Not Found" Then Setup() $passwin = GUICreate("Login", 342, 130, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Group_1 = GUICtrlCreateGroup("Username", 10, 10, 200, 50) $Input_2 = GUICtrlCreateInput($user, 20, 30, 180, 20) $Input_3 = GUICtrlCreateInput($pass, 20, 90, 180, 20, $ES_PASSWORD) $Group_4 = GUICtrlCreateGroup("Password", 10, 70, 200, 50) $Button_5 = GUICtrlCreateButton("Login", 230, 50, 80, 30) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_5 ; check user and password $user = GUICtrlRead($Input_2) $pass = GUICtrlRead($Input_3) If $user = "Not Found" Or $pass = "Not Found" Then Setup() If $user = "Not Found" Or $pass = "Not Found" Then ContinueLoop If $user = "" Or $pass = "" Then ContinueLoop ; if $user and $pass are ok then IniWrite($inipath & "\stoogelog.ini", "Login", "User", $user) IniWrite($inipath & "\stoogelog.ini", "Login", "Password", $pass) GUIDelete($passwin) ExitLoop EndSelect WEnd Func Setup() $user = InputBox("Username", "Enter Name:", "", "", "", 90) If $user = "" Then Exit $pass = InputBox("Password", "Enter Password:", "", "*", "", 90) If $pass = "" Then Exit EndFunc ;==>Setup ;;;;;;;;;;;;;;;;;;;;;;;;;;; START YOUR SCRIPT MsgBox(64, "User", "Username = " & $user & @CRLF & "Password = " & $pass) login type of script thats does as you asked "save info" 8) Link to comment Share on other sites More sharing options...
PsaltyDS Posted September 2, 2006 Share Posted September 2, 2006 (edited) Could someone give a newbie( :"> ) a tip or two on creating and use log files? Like: When first time the program runs it creates a .log file and put a variable into the log file. Next time it is being runed it read the variable and set into the script... Thank you My scripts are mostly for production installation, and I believe in EXHAUSTIVE logging of every action. All my scripts have a standard function near the top something like this: expandcollapse popup#include <file.au3> Global $LogFile If Not _InitLogFile() Then Exit _FileWriteLog($LogFile, "This is my first log entry...") Sleep(1000) ; --------------------- ; Some of the script ; --------------------- _FileWriteLog($LogFile, "This is my second log entry:" & @CRLF & @TAB & "With multiple lines...") ; --------------------- ; The rest of the script ; --------------------- _FileWriteLog($LogFile, "This is my last log entry...") ; Initialize a log file Func _InitLogFile() ; Get script name without .au3 or .exe extention Local $sScriptName = StringReplace(StringReplace(@ScriptName, ".exe", ""), ".au3", "") ; Create unique file name based on script name and run time $LogFile = $sScriptName & "_" & @YEAR & "_" & @MON & "_" & @MDAY & "_" & @HOUR & "_" & @MIN & ".log" ; Check for log dir Local $sLogDir = "C:\Install_Logs" If not FileExists($sLogDir & "\") Then If Not DirCreate($sLogDir) Then MsgBox(16, "Error!", "Could not create log directory: " & $sLogDir) Return 0 EndIf EndIf ; Create file $LogFile = $sLogDir & "\" & $LogFile If _FileWriteLog($LogFile, "Initialized log file: " & $LogFile) Then Return 1 Else MsgBox(16, "Error!", "Could not write to log file: " & $LogFile) Return 0 EndIf EndFunc Run that demo and then check out the log file, you'll see each line has an automated date/time stamp on it. I like it. Edit: Oops... :"> Read it too fast and missed that you meant to pass data, not log events... oh, well. Edited September 2, 2006 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law 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