Jump to content

Reading data from ini file


 Share

Recommended Posts

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
Link to comment
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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Developers

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

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

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
Link to comment
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 :)

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