Sign in to follow this  
Followers 0
Tripredacus

Confused about INI interaction

13 posts in this topic

I am working on a script that deals with reading an INI file. I have read the helpfile and run a search on this forum, but I can't seem to figure out how to do it right. Here is the workflow:

If INI exists then

-if key <> 0 then

-take key, subtract 1, write new value

-run app

-endif

-if key = 0 then

-remove registry key

-delete ini file

-endif

Endif

I have another part of the code I need to do as well, a secondary if statement, but I am sure I can figure out how to do that once I get this idea down. I tried looking for examples of IF arrays, but I got confused as to how you get values and match them from the INI

IF FileExists ("c:\msupdate.ini") Then
; if run is not zero then run app
    If IniRead ("c:\msupdate.ini", "msupdate", "UpdatesRemaining", "2") THEN
        Run(@SystemDir & "\rundll32.exe " & @SystemDir & "\muweb.dll,LaunchMUSite")
    EndIf
EndIf

Share this post


Link to post
Share on other sites



Perhaps:

If FileExists("c:\msupdate.ini") Then
    ; if run is not zero then run app
    $IniValue = Number(IniRead("c:\msupdate.ini", "msupdate", "UpdatesRemaining", 0)) ; You had default = 2?
    If $IniValue Then
        ; data <> 0
        IniWrite("c:\msupdate.ini", "msupdate", "UpdatesRemaining", $IniValue - 1)
        Run(@SystemDir & "\rundll32.exe " & @SystemDir & "\muweb.dll,LaunchMUSite")
    Else
        ; data = 0
        RegDelete($RegKey) ; $RegKey must be defined somewhere...
        FileDelete("c:\msupdate.ini")
    EndIf
EndIf

:shocked:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

I am working on a script that deals with reading an INI file. I have read the helpfile and run a search on this forum, but I can't seem to figure out how to do it right. Here is the workflow:

If INI exists then

-if key <> 0 then

-take key, subtract 1, write new value

-run app

-endif

-if key = 0 then

-remove registry key

-delete ini file

-endif

Endif

I have another part of the code I need to do as well, a secondary if statement, but I am sure I can figure out how to do that once I get this idea down. I tried looking for examples of IF arrays, but I got confused as to how you get values and match them from the INI

IF FileExists ("c:\msupdate.ini") Then
; if run is not zero then run app
    If IniRead ("c:\msupdate.ini", "msupdate", "UpdatesRemaining", "2") THEN
        Run(@SystemDir & "\rundll32.exe " & @SystemDir & "\muweb.dll,LaunchMUSite")
    EndIf
EndIf
The above format seems like it might work, it will probably always return something other than 0 result because you are also setting a default value "2".

You should probably use a variable to hold the output of the IniRead function.

You can try this and see if it works. Work with it to check for a non zero or non null value.

Whichever you need to get it to run the way you need it to.

$iniValue = ""

$iniValue = IniRead ("c:\msupdate.ini", "msupdate", "UpdatesRemaining", "")

If $iniValue Then

Run(@SystemDir & "\rundll32.exe " & @SystemDir & "\muweb.dll,LaunchMUSite")

EndIf

Hope that makes sense.


Be open minded but not gullible.A hammer sees everything as a nail ... so don't be A tool ... be many tools.

Share this post


Link to post
Share on other sites

OK I have this now with the extra part. The second part checks to see if the file does not exist, then it sets the computer up to run the app on a restart. I am using the INI so that it runs it a maximum of 3 times. Once is manually by the user, and on the next 2 reboots. I have found through testing that it usually takes 3 entries into the Windows Update site to get all the ones we need. My original idea was to use the Automatic updates, but it doesn't actually tell you what it is doing. I would rather it launch that instead but this will have to do for now.

; if ini exists Then
If FileExists("c:\msupdate.ini") Then
    ; if run is not zero then run app
    $IniValue = Number(IniRead("c:\msupdate.ini", "msupdate", "UpdatesRemaining", 0)) 
    If $IniValue > 0 Then
        ; data <> 0
        IniWrite("c:\msupdate.ini", "msupdate", "UpdatesRemaining", $IniValue - 1)
        Run(@SystemDir & "\rundll32.exe " & @SystemDir & "\muweb.dll,LaunchMUSite")
    Else
        ; data = 0
        RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" , "msupdate") 
        FileDelete("c:\msupdate.ini")
        Func OnAutoItExit (FileDelete("c:\msupdate.exe"))
        EndFunc
    EndIf
Else 
    FileCopy ("\\server\Install\tools\batch\msupdate.ini","c:\msupdate.ini")
    RegWrite ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run","msupdate","Reg_DWORD","c:\msupdate.exe" )
    Run(@SystemDir & "\rundll32.exe " & @SystemDir & "\muweb.dll,LaunchMUSite")
EndIf

Share this post


Link to post
Share on other sites

Func OnAutoItExit (FileDelete("c:\msupdate.exe"))oÝ÷ Ûú®¢×¢}ýµ×ªÞ~éܶ*'±Ê'v+b¢v¥#î¶ØZµ©eo(­±é_jÛayéÝ¡ûazÇ+ZºÚ"µÍÈY[H^ÝÈ[Y[Q^ÝÊ   ][ÝØÎÌLÛÝ]K[I][ÝÊH[ÈY[ÈÝÈ[[ ÌÍÒ[U[YHH[X[TXY
    ][ÝØÎÌLÛÝ]K[I][ÝË   ][ÝÛÝ]I][ÝË    ][ÝÕ]Ô[XZ[[É][ÝË
JBY ÌÍÒ[U[YH ÝÈ[È]H   ÉÝÈ[UÜ]J    ][ÝØÎÌLÛÝ]K[I][ÝË   ][ÝÛÝ]I][ÝË    ][ÝÕ]Ô[XZ[[É][ÝË  ÌÍÒ[U[YHHJB[ÞÝ[Q   [È ][ÝÉÌLÜ[Ì^H    ][ÝÈ  [ÈÞÝ[Q   [È ][ÝÉÌLÛ]]ÙX][ÚUTÚ]I][ÝÊB[ÙBÈ]HHYÑ[]J    ][ÝÒÑVWÓÐÐSÓPPÒSIÌLÔÓÑÐTIÌLÓZXÜÜÛÙ   ÌLÕÚ[ÝÜÉÌLÐÝ[Ú[ÛÌLÔ[][ÝÈ ][ÝÛÝ]I][ÝÊB[Q[]J  ][ÝØÎÌLÛÝ]K[I][ÝÊB[Y[ÙB[PÛÜH
    ][ÝÉÌLÉÌLÜÙÌLÒ[Ý[ ÌLÝÛÛÉÌLØ]Ú ÌLÛÝ]K[I][ÝË   ][ÝØÎÌLÛÝ]K[I][ÝÊBYÕÜ]H
    ][ÝÒÑVWÓÐÐSÓPPÒSIÌLÔÓÑÐTIÌLÓZXÜÜÛÙ   ÌLÕÚ[ÝÜÉÌLÐÝ[Ú[ÛÌLÔ[][ÝË ][ÝÛÝ]I][ÝË    ][ÝÔY×ÑÓÔ ][ÝË  ][ÝØÎÌLÛÝ]K^I][ÝÈ
B[ÞÝ[Q    [È ][ÝÉÌLÜ[Ì^H    ][ÝÈ  [ÈÞÝ[Q   [È ][ÝÉÌLÛ]]ÙX][ÚUTÚ]I][ÝÊB[YÈXÛH[Ý[ÛÈ[ÛØÜ^][ÈÛ]]Ò]^]

BQ[Q[]J ][ÝØÎÌLÛÝ]K^I][ÝÊB[[

:shocked:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

I haven't gotten to test this one yet, will this even work? I mean the OnExit function... since msupdate.exe IS the app that code is from.

Share this post


Link to post
Share on other sites

I haven't gotten to test this one yet, will this even work? I mean the OnExit function... since msupdate.exe IS the app that code is from.

Probably not. You could use RunWait() instead of Run(). The difference is the waiting for the process to end before continuing the script.

:shocked:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

this code might also help to get you going well with ini logic,

its ini code Im working on at the moment...

imagine an ini file with 2 sections..

[software]

1=app 1

2=app 2

[installstrings]

app 1=c:\soft\installer1.exe

app 2=c:\soft\installer2.exe

then the code would be:

$Software_2_GO = inireadSoftware("inifile.ini","Software")

the function contains this code at the moment:

Func inireadSoftware($IniFile, $IniSection)
$var = IniReadSection($IniFile, $IniSection)
If @error Then 
    MsgBox(4096, "", "Error occurred, no INI file?")
Else
    $Applications = ""
    For $i = 1 To $var[0][0]
;       msgbox(0,"","Application nr:" & $i)
;       MsgBox(4096, "", "Key: " & $var[$i][0] & @CRLF & "Value: " & $var[$i][1])
        if $Applications = "" Then
            $Applications = $var[$i][1]
        Else
            $Applications = $Applications & '|' & $var[$i][1]
        EndIf
    Next
EndIf
;       msgbox(0,"","Applications = " & $Applications)
EndFunc

this code is modified from the helpfiles..

next to get the installation strings into a variable I use:

$Temp_InstStr = IniRead("c:\test.ini", "InstallString", $Software_2_GO, '')

it might not be completely on topic, but I hope the logic becomes more clear from this post..


Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Probably not. You could use RunWait() instead of Run(). The difference is the waiting for the process to end before continuing the script.

:shocked:

It seems that it won't even run the app, it gives a parsing error. I will change it to RunWait() and see what happens.

Line 0
Func OnAutoItExit (FileDelete("c:\msupdate.exe"))
Error: "If" statement has no matching "EndIf" statement

The code is basically the same as in PsaltyDS's post but with different drive paths.

EDIT: I don't know where to put RunWait(). THe only place a Run is located is for it to launch Windows Update. The app itself is launched from an HTML page!

Edited by Tripredacus

Share this post


Link to post
Share on other sites

Line 0
Func OnAutoItExit (FileDelete("c:\msupdate.exe"))
Error: "If" statement has no matching "EndIf" statement

The code is basically the same as in PsaltyDS's post but with different drive paths.

EDIT: I don't know where to put RunWait(). THe only place a Run is located is for it to launch Windows Update. The app itself is launched from an HTML page!

That code is NOT like PsaltyDS's!!! :shocked:

THIS is PsaltyDS's:

; Declare function to run on script exit
Func OnAutoItExit()
    FileDelete("c:\msupdate.exe")
EndFunc

The Func line declares the function. The commands you want inside the fuction go between the Func/EndFunc lines NOT inside the parens.

The only point to RunWait() instead of Run() is to pause the script until the command completes. With just Run() the script will kick off that process and then continue on immediately, reaching the end, exiting, and therefore attempting the OnAutoItExit() function before the Run() is finished.

:(


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Heh... well now...

The cleanup process works in a test environment... it deletes the INI if the setting is 0. But, it does not delete the exe (itself). It also does not close itself.... it remains in the system tray, and as a running process. And Clicking end Process does not make it go away... sorry it eventually finsihed, but the exe remained.

I am confused about using the func... the function should only run after it deletes the INI in the first Else statement.

Edited by Tripredacus

Share this post


Link to post
Share on other sites

The cleanup process works in a test environment... it deletes the INI if the setting is 0. But, it does not delete the exe (itself). It also does not close itself.... it remains in the system tray, and as a running process. And Clicking end Process does not make it go away... sorry it eventually finsihed, but the exe remained.

I am confused about using the func... the function should only run after it deletes the INI in the first Else statement.

One thing I missed before - msupdate.exe is the compiled AutoIt script itself?

It may not be possible for a compiled script to delete itself. The script continuing until the RunWait() functions completed was exactly as intended (by me anyway).

One work-around would be to create a one-time scheduled task to run one minute after the script finishes that deletes the script.

:shocked:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

One thing I missed before - msupdate.exe is the compiled AutoIt script itself?

It may not be possible for a compiled script to delete itself. The script continuing until the RunWait() functions completed was exactly as intended (by me anyway).

One work-around would be to create a one-time scheduled task to run one minute after the script finishes that deletes the script.

:shocked:

It sure was. I still had another app that was to be run when everything else was done, so I put the filedelete in there instead.

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