Jump to content

Reading and checking unexistent INI Key


James
 Share

Recommended Posts

Hi,

I know my title was a bit weird but its the only way I can explain it in a few words.

I am in need of some INI help. Here is what I want to do:

  • Read INI section for a key value:
  • If it exists then all is ok
  • If not then:
  • Write value

Global $Ini = @SystemDir & '\oeminfo.ini'

$OEMIni = IniReadSection($Ini, "Support Information")
For $ax = 1 To $OEMIni[0][0]
    If StringInStr("Line8=Created using OEM Branding Wizard by James Brooks", IniRead($OEMIni[$ax][1], "Support Information", "Line8", "Created using OEM Branding Wizard by James Brooks")) Then
        ConsoleWrite("Found wizard information!" & @CRLF)
        ExitLoop
    ElseIf Not IniRead($OEMIni[$ax][1], "Support Information", "Line8", "Created using OEM Branding Wizard by James Brooks") Then
        IniWrite($OEMIni[$ax][1], "Support Information", "Line8", "Created using OEM Branding Wizard by James Brooks")
        ConsoleWrite("Information added!" & @CRLF)
        ExitLoop
    EndIf
Next

Information:

OEMinfo.ini is set out like:

[General]

Manufacturer=OEMBrandingWizard.au3

Model=1.5.3.6

[support Information]

Line1=Test

Line2=Me

Line3=Out

Line4=2008

Line5=OEM Branding Wizard

Line6=

Line7=James Brooks

I need to add a "Line8" and the key = "Created using OEM Branding Wizard by James Brooks"

Thanks,

James

Link to comment
Share on other sites

Have you looked at the IEAK? It sets up customizing of the browser and OEM info shown in computer properties tab and perhaps some more.

IniReadSection() sets the @error macro if the file or section does not exist. It is not shown in your script and IMO it should be there to help it work. Don't just expect something, always try to check if your script can.

:)

Link to comment
Share on other sites

Looks like you are mixing IniReadSection with Iniread which would usually be one or the other so I changed your code a little to show hopefully a working model for view.

Global $Ini = @SystemDir & '\oeminfo.ini'

$OEMIni = IniReadSection($Ini, "Support Information")
If Not @error Then
    ; Search for the desired value
    $found_the_value = False
    For $ax = 1 To $OEMIni[0][0]
        If StringInStr($OEMIni[$ax][1], 'Created using OEM Branding Wizard by James Brooks') Then
            ConsoleWrite("Found wizard information!" & @CRLF)
            $found_the_value = True
            ExitLoop
        EndIf
    Next
Else
    ; Add if no section or file
    IniWrite($Ini, "Support Information", "Line8", "Created using OEM Branding Wizard by James Brooks")
    ConsoleWrite("Information added!" & @CRLF)
EndIf

; Add value into the ini if the value does not exist
If Not $found_the_value Then
    IniWrite($Ini, "Support Information", "Line8", "Created using OEM Branding Wizard by James Brooks")
    ConsoleWrite("Information added!" & @CRLF)
EndIf

But checking for the value does not mean that it is with the correct key that you may expect so you need to decide which ini function handles your task the way that you want it to.

Edited by MHz
Link to comment
Share on other sites

Thanks, however I get this error:

C:\Documents and Settings\James\My Documents\OEMBrandCheck.au3 (28) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: 
IniWrite($OEMIni[$ax][1], "Support Information", "Line8", "Created using OEM Branding Wizard by James Brooks") 
IniWrite(^ ERROR

Just going to fix that. I see what I did wrong now!

WTH? It doesn't do anything even if I remove that code.

Edited by JamesB
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...