Sign in to follow this  
Followers 0
damon

Iniread Problems

13 posts in this topic

I am a 6 month newbe to autoit, I really like the program.

Ok, I am currently working on a 2400 line script that will install and configure a massive amount of software.

The breakdown of the script is, A tech will run the setup.exe (autoit script compiled). It will install a set of software, Write a config.ini file and then it adds

RegWrite ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "ScannerSetup", "REG_SZ",@ScriptDir & "\setup.exe")

this is done so that it will startup on the next reboot and continue where the installation left off using select case. I have even tried it using

FileCreateShortcut (@ScriptDir & "\setup.exe", @StartupDir & "\setup scanner 3-5-2010.lnk") thinking that maybe it would make a difference.

When it reboots the program starts, but from the case 1 like it had never been run. Case 2 is where it should pickup from and start running.

I tried putting a msgbox in to show me what the variable returned and it was blank. So I thought that I was calling it wrong or maybe a syntax error. Here is the kicker, after startup and it fails to work right I can start it manually and it works great.

Here is the script, I have cut everything out but the basics to keep you from having to decifer 2400 lines of code.

Thanks in advance.

#include <File.au3>

$Install_progress = IniRead (@ScriptDir & "config.ini", "Installation_Progress", "Progress", "")


WinMinimizeAll ()
MsgBox (0,"ini value", IniRead (@ScriptDir & "config.ini", $install_progress)
MsgBox (0,"ini value", IniRead (@ScriptDir & "config.ini", "Installation_Progress", "Progress", ""))
;;If this is a first time installation it will display this message
Select
     Case $install_progress <= 1
    IniWrite ("config.ini", "Installation_Progress", "Progress", "2")
    ;;FileCreateShortcut (@ScriptDir & "\setup.exe", @StartupDir & "\setup scanner 3-5-2010.lnk")
    RegWrite ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "ScannerSetup", "REG_SZ",@ScriptDir & "\setup.exe")
    Shutdown (22)
    Exit
;;---------------------------------------------------------------------------------------------------------------------------------------------------
    ;;This is the start of the second Boot Process
    Case $install_progress = 2
        IniWrite ("config.ini", "Installation_Progress", "Progress", "3")
        Shutdown (22)
        Exit
;;---------------------------------------------------------------------------------------------------------------------------------------------------
    Case $install_progress = 3
        IniWrite ("config.ini", "Installation_Progress", "Progress", "4")
        Shutdown (22)
        Exit
;;------------------------------------------------------------------------------------------------------------------------------
    Case $install_progress = 4
        IniWrite ("config.ini", "Installation_Progress", "Progress", "5")
        Exit
;;-------------------------------------------------------------------------------------------------------------------------------
    Case $install_progress = 5
        MsgBox ( 0, "Installation Complete", "The software has been installed")
    EndSelect




Exit

It always amazes me how one little thing can cause so much havoc

Share this post


Link to post
Share on other sites



Does this work?

$Install_progress = IniRead (@ScriptDir & "\config.ini", "Installation_Progress", "Progress", "")

Is the file actually being created? I had a similar issue and @scriptdir wasn't putting an end slash, so it was like c:\temp so the ini became c:\tempconfig.ini so i added the slash so it became c:\temp\install.ini

Not sure if this is whats causing yours

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

sorry, you are right. I just tried adding @scriptdir this morning and forgot to put slash.

This is what I have been using and it works but not at startup.

Sorry, to much coding.

[autoit]#include <File.au3>

$Install_progress = IniRead ("config.ini", "Installation_Progress", "Progress", "")

WinMinimizeAll ()

MsgBox (0,"ini value",$install_progress)

MsgBox (0,"ini value", IniRead (@ScriptDir & "\config.ini", "Installation_Progress", "Progress", ""))

;;If this is a first time installation it will display this message

Select

Case $install_progress <= 1

IniWrite ("config.ini", "Installation_Progress", "Progress", "2")

;;FileCreateShortcut (@ScriptDir & "\setup.exe", @StartupDir & "\setup scanner 3-5-2010.lnk")

RegWrite ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "ScannerSetup", "REG_SZ",@ScriptDir & "\setup.exe")

Shutdown (22)

Exit

;;-----------------------------------------------------------------------------------------------------------------------------------------------------------------

;;This is the start of the second Boot Process

Case $install_progress = 2

IniWrite ("config.ini", "Installation_Progress", "Progress", "3")

Shutdown (22)

Exit

;;----------------------------------------------------------------------------------------------------------------------------------------------------------

Case $install_progress = 3

IniWrite ("config.ini", "Installation_Progress", "Progress", "4")

Shutdown (22)

Exit

;;------------------------------------------------------------------------------------------------------------------------------

Case $install_progress = 4

IniWrite ("config.ini", "Installation_Progress", "Progress", "5")

Exit

;;-------------------------------------------------------------------------------------------------------------------------------

Case $install_progress = 5

MsgBox ( 0, "Installation Complete", "The software has been installed")

EndSelect

Exit

Edited by damon

It always amazes me how one little thing can cause so much havoc

Share this post


Link to post
Share on other sites

have you opened your ini file to see what the values were that it writes? it looks like from what you last posted that perhaps the info isn't getting to the ini. try

IniWrite ( @ScriptDir & "\config.ini", "Installation_Progress", "Progress", "4")


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

yeah, the ini file writes correctly, but when I try running it at startup it acts like it is not reading from the ini file. If i run the setup by just clicking it then it works great, reads the file and starts at case =2. I feel like it may be a bug but i am not experienced enough to make that call.


It always amazes me how one little thing can cause so much havoc

Share this post


Link to post
Share on other sites

I have been building this script for about 2 months now, I have broke it up into sections to make sure that it works as I go along. The ini file is depending on the computer it is being installed on about 60 to 100 lines. I have it broke up into sections and keep looking at it thinking something has changed but it is always reading correctly.


It always amazes me how one little thing can cause so much havoc

Share this post


Link to post
Share on other sites

bah, I think I know what it is...

after the iniread, conver the result to int. it is currently in string format and you are comparing to int.

($install_progress = 3) is int

($install_progress = "3") is string


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

no antivirus or adware program picking up that its written to Windows\Run and deleting it?

What about adding a MsgBox just before and after the place it should pick up after the reboot. so if it displays the message box it is obviously starting the script, if not, then something is stopping the script from even being run?

Share this post


Link to post
Share on other sites

Koatkbliss --- would this make a difference being that it works if i just run the file, because when I just run the file it works and starts at second case like it is suppose to, but when it is run from startup or Run in the Registry it does not.

darkleton --- The script will run, I put a message box after the ini read to display the value which will display the value "2" (which is the value that i expect it to return). then it starts at the first case which should only start if <=1. Now if i exit the script and restart it, it will give the value "2" again and start at case =2. I do not understand why running on startup/registry Run causes it to bomb out.


It always amazes me how one little thing can cause so much havoc

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

I had a similar issue with a game I was working on, it would save the characters position to an ini file (which saved correctly) but right before loading the character lost the numbers because what was needed was integers and iniread was outputting a string.

Also maybe try another switch

Select Case <expression> If the expression is true the following statements up to the next Case or EndSelect statement are executed. If more than one of the Case statements are true, only the first one is executed.

Switch Case <expression> An expression that returns a value. The value from the expression is then compared against the values of each case until a match is found. This expression is always evaluted exactly once each time through the structure.

the 2nd is probably what you want

*edit*

basically what I am trying to say is 1+1 as integer returns 2

1+1 as string returns 11 (oneone, not eleven)

while visually they look the same, they are interpreted differently.

*2nd edit*

ok, not exactly true as the return value, but the point is still the same: it's safer to match string to string and integer to integer

Edited by kaotkbliss

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

I tried

$Install_pro = IniRead (@ScriptDir & "\config.ini","Installation_Progress", "Progress", "") 
$install_progress = int ($install_pro)

It did the same thing, it returned varable of "2" and then it started at the first case <=1 agian.

I exited and restarted (not on boot) the setup.exe by clicking on it and it started on second case =2 like it is suppose to do. Still not running correctly on bootup though.

as you can see I am currently running a select case(as of this morning), I however have been using switch case for the past 4 days with the same results, and before that I was using IF Then with the same results.

It works everytime correctly if I personally start it.... but if it is started by registry or startup it starts from the begining of the script without checking for select case, switch case, If Then.

Edited by damon

It always amazes me how one little thing can cause so much havoc

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Another miss on my part...

you define the variable as

$Install_progress

then later try to call is as

$install_progress

Edited by kaotkbliss

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

I got it working, thanks kaotkbliss

it was giving me parse errors when i was changing my $install_progress to a int. I ended up closing autoit and restarting it, recompiling the file and it worked great.

thanks for all the help


It always amazes me how one little thing can cause so much havoc

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