Sign in to follow this  
Followers 0
ViciousXUSMC

Read a Log File, Find String, Read Line to MsgBox

3 posts in this topic

I wanted to make a little script to easily check if the current Windows install is using Legacy or EFI Bios/Install as this matters for how we capture/deploy an image for the machine.

I think the easiest way for us to do that is to look at the log file located at C:WindowsPanthersetupact.log and in that file will be a string of text "Detected boot environment:" followed by the information I need.

I constructed a very crude script seen below just using an if statment to see if it matches or not, but I really want to clean this up so that it find the string and then displays the entire resulting line instead.  This way I see the real information rather than my interpretation of it and I can also use @error to notify me if nothing was found.

Here is my script below, does anybody mind pointing me in the right direction.  I swear I have done this before but forgot how I accomplished it.

$boot = FileOpen("C:\Windows\Panther\setupact.log")
$boot2 = FileRead($boot)
$boot3 = StringinStr($boot2, "Callback_BootEnvironmentDetect: Detected boot environment: BIOS")
If $boot3 = 0 Then
    MsgBox(0, "Black Magic Tools", "Detected Windows Install as EFI Type")
Else
    MsgBox(0, "Black Magic Tools", "Detected Windows Install as BIOS (Legacy) Type")
EndIf

FileClose($boot)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try something like this. Read line by line so we don't have to read the whole log, in case it is large.

Do
   $sLine = FileReadLine($boot)
   If(@error > 0) Then
     SetError(1) ; Could not read file
   ElseIf(@error = 0 AND StringInStr($sLine, "Detected boot environment:")) Then
      If(StringInStr($sLine, "BIOS")) Then
         ; Here BIOS was detected
         ; Do whatever you need depending on the detected environment
      EndIf
      FileClose($boot)
      MsgBox(0, "Black Magic Tools", $sLine)
      ExitLoop ; No need to continue
   EndIf
      
Until(@error < 0) ; End of file
FileClose($boot)

 * Edited: Use MsgBox as requested, not ConsoleWrite. Fixed logic.

Edited by mwhidden

Share this post


Link to post
Share on other sites

$sInstallType = "unknow"

$sContent = FileRead("C:\Windows\Panther\setupact.log")

$aType = StringRegExp($sContent, "(?i)Callback_BootEnvironmentDetect: Detected boot environment: (BIOS|UEFI)", 1)
If IsArray($aType) Then $sInstallType = $aType[0]

ConsoleWrite("Installation type : " & $sInstallType)

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