Jump to content

ini file update


Recommended Posts

i want to check if a key in an ini file has a certain value if it is i need to change it , if the key doesn't exist in need to write some new entries to the ini file.

here is the code i have so far but all it does is write the entry after the then statement and skips everything else

If IniRead("C:\WINNT\class.ini", "New Trainer", "DatabaseName", "class") = "class" Then

Iniwrite("C:\WINNT\class.ini", "New Trainer", "DatabaseName", "trainer")

Else

IniWrite("C:\WINNT\class.ini", "Databases", "New Class", "")

IniWrite("C:\WINNT\class.ini", "Databases", "New Trainer", "")

EndIf

any help would be appreciated

Link to comment
Share on other sites

ok i'm trying to check a key in an ini file to see if it is set to class if it is i need to change it to trainer, if the key is set to trainer i dont need to do anything. if the key is not there i need to add it

Edited by rinaldm
Link to comment
Share on other sites

  • Developers

First time you run it the ini contains:

[New Trainer]DatabaseName=trainer

Second and subsequent times it contains:

[New Trainer]DatabaseName=trainer

[Databases]

New Class=

New Trainer=

So thats exactly what you have coded in the script.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

i  want to check if a key in an ini file has a certain value if it is i need to change it , if the key doesn't exist in need to write some new entries to the ini file.

here is the code i have so far but all it does is write the entry after the then statement and skips everything else

If IniRead("C:\WINNT\class.ini", "New Trainer", "DatabaseName", "class") = "class" Then

  Iniwrite("C:\WINNT\class.ini", "New Trainer", "DatabaseName", "trainer")

Else

  IniWrite("C:\WINNT\class.ini", "Databases", "New Class", "")

  IniWrite("C:\WINNT\class.ini", "Databases", "New Trainer", "")

EndIf

any help would be appreciated

I'm not quite getting it myself but here's a basic idea

$var=iniread("path\my.ini,"Section","key","DefaultValue")

;now if it's does not exist it will give the defaultvalue. If it does exist but is blank it will be empty so

if $var="defalutvalue" or $var="" then

iniwrite("path\my.ini","Section","key","MyNewValue")

endif

Hope that helped

Rick

Link to comment
Share on other sites

  • Developers

Like this ? :

If IniRead("C:\WINNT\class.ini", "New Trainer", "DatabaseName", "") = "class" Then
   Iniwrite("C:\WINNT\class.ini", "New Trainer", "DatabaseName", "trainer")
Else
   IniWrite("C:\WINNT\class.ini", "Databases", "New Class", "")
   IniWrite("C:\WINNT\class.ini", "Databases", "New Trainer", "")
EndIf

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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...