Jump to content

Recommended Posts

Posted (edited)

Hi everyone :)

Hope you're doing great today. ;)

Well, I have a little question about extracting a certain string from a file name to make comparison after treatment.

Let's get into the details:

First of all, I gather and store a machine BIOS Version by running this:

RunWait(@ComSpec & " /c " & "wmic bios get SMBIOSBIOSVERSION >> C:\Drivers\Tag.txt" & @CRLF, "", @SW_HIDE, "$STDOUT_CHILD")
_FileWriteToLine("c:\Drivers\BIOS_Version.txt", 1, "", 1)
$sContent = FileRead ("C:\Drivers\BIOS_Version.txt")
$sContent = StringRegExpReplace($sContent, " ", "")

Result is, for example, A10

Then, I download the latest available BIOS version from the Dell related model website and the filename of the latest BIOS is stored in a $sBIOSName variable.

Result is for example, E5440A14.exe

What i can't figure out is how to extract the Bios name stored in the $sBIOSName knowing that each model this app would run won't have the same number of chars.
Indeed, I have some OPL790AXX.exe / OPL7010AXX.exe / E5470AXX.exe etc...

I imagine something like getting the whole string, left trimming it to the first A found count 2 chars on the right and store them to have the possibility to make the check between A10 and A14 (as the number of char of filenames is never the same)

Hope this is clear :) If not, don't hesitate to ask for more.
Thanks in advance for the help :)

 

Edited by 31290

~~~ Doom Shall Never Die, Only The Players ~~~

Posted

Use StringInStr to get the position of the first "A" and then use this as starting position for your calculation.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

Hi Water :)

Thanks for the reply.

Indeed, I just found this way to do so:

RunWait(@ComSpec & " /c " & "wmic bios get SMBIOSBIOSVERSION >> C:\Drivers\Tag.txt" & @CRLF, "", @SW_HIDE, "$STDOUT_CHILD")
_FileWriteToLine("c:\Drivers\BIOS_Version.txt", 1, "", 1)
$sContent = FileRead ("C:\Drivers\BIOS_Version.txt")
$sContent = StringRegExpReplace($sContent, " ", "")
$sMidBIOSNAME = StringInStr ($sBIOSName, "A")
$sFinalBIOSNAME = StringMid($sBIOSName, $sMidBIOSNAME, 3)
msgbox (0, "", $sFinalBIOSNAME)

I got the expected result. 

Do you think this can be optimized / shortened or not? (just curious ^^)

~~~ Doom Shall Never Die, Only The Players ~~~

Posted

RegExp's are most of the time shorter than regular AutoIt functions. But don't forget to add comments so you still know what the RegExp does in a few months.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

Hello. Just for fun.

 

$str = "   OPL790A12.exe   "
Msgbox(0,"",StringMid($str,StringInStr($str,".exe")-3,3))

Saludos

Posted

Or use "Scriptomatic" to generate the WMI query for you. It assigns the result to an variable or array.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

Script get the version wrong syntax:

RunWait(@ComSpec & " /c " & "wmic bios get SMBIOSBIOSVERSION >> C:\Drivers\Tag.txt" & @CRLF, "", @SW_HIDE, "$STDOUT_CHILD")

TO:

RunWait(@ComSpec & " /c " & "wmic bios get SMBIOSBIOSVERSION" & @CRLF, "", @SW_HIDE, $STDOUT_CHILD)
;::OR
RunWait(@ComSpec & " /c " & "wmic bios get SMBIOSBIOSVERSION >> C:\Drivers\Tag.txt" & @CRLF, "", @SW_HIDE, $STDOUT_CHILD)

and something useful:

Local $iPID = Run('"' & @ComSpec & '" /c ' & 'wmic bios get SMBIOSBIOSVERSION', '', @SW_HIDE, 0x2) ;$STDOUT_CHILD (0x2)
ProcessWaitClose($iPID)
Local $sSMBIOSBIOSVersion = StdoutRead($iPID)
$sSMBIOSBIOSVersion = StringStripWS(StringReplace(StringReplace($sSMBIOSBIOSVersion, "SMBIOSBIOSVersion", ""), " ", ""), 8)

Local $hFileOpen = FileOpen("C:\Drivers\BIOS_Version.txt", 2 + 8)
FileWrite($hFileOpen, $sSMBIOSBIOSVersion)
FileClose($hFileOpen)

ConsoleWrite($sSMBIOSBIOSVersion & @CRLF)
;~ ConsoleWrite(@CRLF & _WMI_SingleQuery("Win32_BIOS", "Manufacturer") & @CRLF)
;~ ConsoleWrite(@CRLF & _WMI_SingleQuery("Win32_BIOS", "SMBIOSBIOSVERSION") & @CRLF)
;~ ConsoleWrite(@CRLF & _BIOSinfo() & @CRLF)

Func _BIOSinfo($sComputer = ".")
    Local $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $sComputer & "\root\CIMV2")
    Local $Output, $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_BIOS", "WQL", 0x10 + 0x20)
    If IsObj($colItems) Then
        For $objItem In $colItems
            $Output &= $objItem.BIOSVersion(0) & @CR
            $Output &= $objItem.Manufacturer & @CR
            $Output &= $objItem.SMBIOSBIOSVersion
            Return $Output
        Next
    EndIf
EndFunc   ;==>_BIOSinfo

Func _WMI_SingleQuery($sClass, $sProperty, $sComputer = ".")
    Local $objWMI = ObjGet("winmgmts:\\" & $sComputer & "\root\CIMV2")
    Local $objInstances = $objWMI.InstancesOf($sClass)
    Local $count = $objInstances.Count
    If @error Or Not $count Then Return SetError(1, 0, "") ;"Object Error"
    For $objItem In $objInstances
        For $objProperties In $objItem.Properties_()
            If ($objProperties.Name = $sProperty) Then Return $objProperties.Value
        Next
    Next
    Return SetError(2, 0, "") ;"Nothing Found"
EndFunc   ;==>_WMI_SingleQuery

 

Regards,
 

Posted

Many thanks all for your inputs, much appreciated!

Have a great day!

~~~ Doom Shall Never Die, Only The Players ~~~

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
×
×
  • Create New...