antmar904

Get contents of file

8 posts in this topic

#1 ·  Posted (edited)

Hi,

I am trying to read the log file for the Internet Explorer 11 installation located @ C:\Windows\IE_main.log and search for the setup exit code.

The line that I am trying to get the setup exit code always begins with "Setup exit code:" then the exit code and some text.

Exp:

Setup exit code: 0x00000BC2 (3010) - Installation Succeeded. Reboot required.

OR 

Setup exit code: 0x00009C59 (40025) - The neutral cab failed to install.

How would I get the contents of the whole line that states the "Setup exit code"?

This is what I have so far but is not working

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>

Local $Results = "unknown"
Local $IE11Log = ("C:\Temp\IE_main.log") ;Test log file location
Local $hFileOpen = FileOpen($IE11Log, 0)
Local $Content = FileRead($hFileOpen)
If StringInStr($Content, "Setup exit code:") Then
Local $String = StringRegExp($Content, "(?i)Setup exit code:")
If IsArray($String) Then $Results = $String[0]
MsgBox("", "Results", $Results)

 

Edited by antmar904

Share this post


Link to post
Share on other sites



Try my bad script:

Local $Results = "unknown"
Local $IE11Log = "C:\Temp\IE_main.log"
Local $Content = FileReadToArray($IE11Log)
If IsArray($Content) Then
    For $i = 0 To UBound($Content) - 1
        If StringInStr($Content[$i], "Setup exit code:") Then
            $Results = StringReplace($Content[$i], "Setup exit code:", "")
            MsgBox(0, "Results", $Results)
        EndIf
    Next
EndIf

 


“The world won’t care about your self-esteem. The world will expect you to accomplish something Before you feel good about yourself.”

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

@wayfarer

nothing is returned, no msgbox pops up.

 

@mikell

I'm still getting a msgbox with results "unknown"

I've attached a sample of the IE11 install log file and would like to caputre that line that contains "Setup exit code:"

IE11_main.log

Edited by antmar904

Share this post


Link to post
Share on other sites

antmar904,

Using the "IE11_main.log" you posted, the previous code works for me

Local $Content = FileRead("IE11_main.log")
Local $aString = StringRegExp($Content, "(?i)Setup exit code:\N+", 3)
If IsArray($aString) Then $Results = $aString[0]
MsgBox("", "Results", $Results)

 

Share this post


Link to post
Share on other sites
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>

Local $Results = "unknown"
Local $IE11Log = "C:\Temp\IE_main.log" ;Test log file location
Local $hFileOpen = FileOpen($IE11Log, 0)
If @error Then
    MsgBox (0, "error", "error")
    Exit
EndIf
Local $Content = FileRead($hFileOpen)
Local $aString = StringRegExp($Content, "(?i)Setup exit code:\N+", 3)
If IsArray($aString) Then $Results = $aString[0]
MsgBox("", "Results", $Results)

Capture.JPG.61875de57fe40472703a01111c68

Share this post


Link to post
Share on other sites

In your code if I replace

Local $IE11Log = "C:\Temp\IE_main.log"

by

Local $IE11Log = "C:\Temp\IE11_main.log"

then it works  :)

Share this post


Link to post
Share on other sites

OMG the log file path was wrong, I was missing the (11) in IE11_main.log.

Its been a long day.

Thank you very much for your help!!!

 

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