James Posted February 20, 2008 Share Posted February 20, 2008 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 okIf 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 Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
MHz Posted February 20, 2008 Share Posted February 20, 2008 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 More sharing options...
James Posted February 20, 2008 Author Share Posted February 20, 2008 Thanks for the tip of IEAK! I shall look at that later I have tried using @error but I don't get anywhere.. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
MHz Posted February 20, 2008 Share Posted February 20, 2008 (edited) 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 February 20, 2008 by MHz Link to comment Share on other sites More sharing options...
James Posted February 20, 2008 Author Share Posted February 20, 2008 (edited) 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 February 20, 2008 by JamesB Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
MHz Posted February 20, 2008 Share Posted February 20, 2008 Sorry, check the edit above. Link to comment Share on other sites More sharing options...
James Posted February 20, 2008 Author Share Posted February 20, 2008 Thanks Mhz! Big help! Thanks! Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now