Jump to content
Sign in to follow this  
MystrE

Problems logging

Recommended Posts

MystrE

I am very new to autoit, been using it for a week and i've hit a roadbump.

I'm able to install programs with the code below and now my question is how do i create a log file that says "Installation succesfull" and "Installation not succesfull". I don't want it to pop-up in a messagebox just want to be able to export it to a .txt file where it has the "Year-month-day-hour-minute | Installed succesfull / Not succesfull"

Global $iniFileProg = @ScriptDir & "\Prog.ini"
Global $iniFileNetwork = @ScriptDir & "\Network.ini"

Local $username = IniRead($iniFileNetwork, "Netwerk", "Username", "NotFound")
Local $domain = IniRead($iniFileNetwork, "Netwerk", "Domain", "Not Found")
Local $password = IniRead($iniFileNetwork, "Netwerk", "Password", "Not Found")
Local $path = IniRead($iniFileNetwork, "Netwerk", "Netpath", "Not Found")
Local $scriptDir = IniRead($iniFileProg, "Programma", "ScriptDir", "Not Found")
Local $filename = IniRead($iniFileProg, "Programma", "Filename", "Not Found")
Local $switch = IniRead($iniFileProg, "Programma", "Switch", "Not Found")

RunAsWait($username, $domain, $password, 2, '"' & $path & $scriptDir & "\" & $fileName & '"' & " " & $switch)
Exit

Share this post


Link to post
Share on other sites
MystrE

I have and i found the _FileWriteLog Function, but i just can't figure it out. It doesn't matter how i configure it it always gives out an log file with "Succesfull" even if the program hasn't started to run.

Share this post


Link to post
Share on other sites
MystrE

Hey Jos,

Sorry for the late reply.

I've found a workaround for the problem ( looking in the forums and searching for a couple of days )

#include <file.au3>

Global $iniFileProg = @ScriptDir & "\Prog.ini"
Global $iniFileNetwork = @ScriptDir & "\Network.ini"

Local $username = IniRead($iniFileNetwork, "Netwerk", "Username", "NotFound")
Local $domain = IniRead($iniFileNetwork, "Netwerk", "Domain", "Not Found")
Local $password = IniRead($iniFileNetwork, "Netwerk", "Password", "Not Found")
Local $path = IniRead($iniFileNetwork, "Netwerk", "Netpath", "Not Found")
Local $scriptDir = IniRead($iniFileProg, "Programma", "ScriptDir", "Not Found")
Local $filename = IniRead($iniFileProg, "Programma", "Filename", "Not Found")
Local $switch = IniRead($iniFileProg, "Programma", "Switch", "Not Found")

$LogFile = @ScriptDir & "\" & @ScriptName & "_" & @YEAR & "_" & @MON & "_" & @MDAY & "-" & @HOUR & @MIN  & ".log"
If Not _FileWriteLog($LogFile, "Initialized script from: " & @ScriptFullPath) Then
     MsgBox(16, "Error!", "Could not initialize log file!  Exiting...")
     Exit
EndIf


RunAsWait($username, $domain, $password, 2, '"' & $path & $scriptDir & "\" & $fileName & '"' & " " & $switch)

If FileExists("C:\Program Files (x86)\7-Zip\")  Then
     _FileWriteLog($LogFile, "Programma is al ge-installeerd " & @ScriptName)
Else
     If RunAsWait($username, $domain, $password, 2, '"' & $path & $scriptDir & "\" & $fileName & '"' & " " & $switch) Then
          _FileWriteLog($LogFile, "Programma succesvol ge-installeerd: " & @ScriptName)
     Else
          _FileWriteLog($LogFile, "Programma niet succesvol ge-installeerd: " & @ScriptName)
     EndIf
EndIf
Exit

THe only problem here is now that it looks for the folder of the installation if it exists, but if the installation stops halfway and still makes the folder the log isn't right.

I'd like to log the progress in a .txt file of an installed file. So like the on that is written now :

2013-10-08 09:14:33 : Initialized script from: C:\7Zip.au3
2013-10-08 09:14:33 : Programma niet succesvol ge-installeerd: 7Zip.au3

But with another entry like "Initializing script" / "Program installed Started" / "Program installed succesfully or Program installation Failed"

Sorry for the confusion Jos, like i said i'm very new to autoit and to programming so i'm still puzzling around and searching the help and forums for tips

EDIT-

Something like '?do=embed' frameborder='0' data-embedContent>> Post #6 by PsaltyDS. He explains here how it's done for the function dircreate, i would like to do the same with runwait. Please if it's possible could you help, or at least direct me to the page where i can find the info on how to do this. That would be great :)

Edited by MystrE

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  

×