Sign in to follow this  
Followers 0
jbennett

Reading data from ini file

7 posts in this topic

#1 ·  Posted (edited)

Hi everyone,

Got a bit of an issue with reading an ini file in AutoIT and was wondering if anyone knows what could be wrong, so here goes.

1 - My Ini file

[TARGET]

targetlocation="notepad.exe"

[PARAMETERS]

theparameters=""

2 - AutoIT read ini

$targetlocation = IniRead("C:\Configuration.ini", "TARGET", "targetlocation", "")

$parameters = IniRead("C:\Configuration.ini", "PARAMETERS", "theparameters", "")

3 - AutoIT code

shellexecute ($targetlocation,$parameters,"")

I think the problem is with "3 - AutoIT code"

Hope someone knows what's going wrong here. Thanks

Edited by jbennett

Share this post


Link to post
Share on other sites



I can't see what's wrong with your code.

I normally use the 'Run' command:

Dim $App2Launch

Dim $App2Launch_Path

Dim $App2Launch_CmdLineParam

Dim $RunMode

.....Iniread section, assigning values to the vars....

$App2Launch_PID=Run($App2Launch_Path & $App2Launch & " " & $App2Launch_CmdLineParam,"",$RunMode)


If you learn from It, it's not a mistake

Share this post


Link to post
Share on other sites

Strange. Going to try it again :-)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

It seems to work out of a loop, but as soon as I put it in my loop it decides to fail.

While 1

Sleep(1000)

If int(@HOUR)=$hour1 And int(@Min)=$minute1 And int(@Sec)=$second1 Then

Sleep(1000)

shellexecute ($targetlocation,$parameters)

endif

WENd

and the code above works fine if I put shellexecute ("notepad.exe","")

Very strange?

Edited by jbennett

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

It seems to work out of a loop, but as soon as I put it in my loop it decides to fail.

and the code above works fine if I put shellexecute ("notepad.exe","")

How are these variables set and aqre you sure they are numeric and not strings?

Its risky business to sleep 1 second and test for :

If int(@HOUR)=$hour1 And int(@Min)=$minute1 And int(@Sec)=$second1 Then

I would change that to Sleep(500) to ensure you are not skipping the second you are testing for.

also: what is failing? are you getting any kind of error?

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Nope, not getting any error

This works

While 1

Sleep(1000)

If int(@HOUR)=$hour1 And int(@Min)=$minute1 And int(@Sec)=$second1 Then

Sleep(1000)

shellexecute ("notepad.exe","")

endif

WENd

This doesn't work

While 1

Sleep(1000)

If int(@HOUR)=$hour1 And int(@Min)=$minute1 And int(@Sec)=$second1 Then

Sleep(1000)

shellexecute ($targetlocation,$parameters)

endif

WENd

and the only different is the shellexecute bit.

I'm not using notepad.exe. Im using ($targetlocation,$parameters)

cheers

Edited by jbennett

Share this post


Link to post
Share on other sites

IMO - there is nothing wrong with ShellExecute.

From my experience - if you try to match a time high chances are that it will fail. Why? Because of the Sleep inside the loop and the time it takes to execute the code; it is very easy that $second1 to be missed. I bet either code will be executed flawlessly if you change this line:

If int(@HOUR)=$hour1 And int(@Min)=$minute1 And int(@Sec)>$second1 Then

But in order to do that you will need to add something extra (to increment the time so the script won't run every cycle).

$targetlocation = "notepad.exe"
$parameters = ""

$hour1 = 9          ;change values for your time
$minute1 = 59
$second1 = 15

While 1
    Sleep(500)
    If int(@HOUR)=$hour1 And int(@Min)=$minute1 And int(@Sec)>$second1 Then 
        Sleep(1000)
        shellexecute ($targetlocation,$parameters)
        $second1 += 30      ;adds 30 sec = it will run notepad again after 30 sec
    endif
WENd

Change the time values to suit your needs and test it, you will see how well it works.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

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