Sign in to follow this  
Followers 0
PantZ4

Log files?

4 posts in this topic

Could someone give a newbie( :"> ) a tip or two on creating and use log files? :nuke:

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 :P

Share this post


Link to post
Share on other sites



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 :P

Check out IniWrite and IniRead in the help file. I think that's what you are looking for.

:nuke:

Share this post


Link to post
Share on other sites

here is a login that uses two approaches, a GUI and Inputbox

#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)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 :P

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:

#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.

:nuke:

Edit: Oops... :"> Read it too fast and missed that you meant to pass data, not log events... oh, well.

Edited 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

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0