Jump to content

Parameters Before Running


Doll
 Share

Recommended Posts

I would like to know if this is possible. I want to set my AutoIt program to run only with proper parameters only.

So if you run it without the parameters or other parameters, it won't run.

It's like when you right-clicked a shortcut in your desktop, you'll have a parameters in the Target first.

Target: "C:\AutoIt.exe" -START

So I want to set my AutoIt.exe to run when parameter "-START" is applied.

Could someone give me a sample or at least answer my question?

Smile. :)

Link to comment
Share on other sites

Look up Command Line Parameters in Help-file section 'Running Scripts'.

If @Compiled Then
    if ($CmdLine[0] = 0) or ($CmdLine[0] > 0 AND NOT StringInStr($CmdLine[1], "-START")) Then
        MsgBox(0,'','Wrong CmdLine Parameters, program start canceled!')
        Exit
    EndIf
EndIf

GUICreate("test", 230, 90)
GUISetState()

While 1
    $msg = GUIGetMsg()
    If $msg = -3 Then ExitLoop
    sleep(5)
WEnd
Edited by KaFu
Link to comment
Share on other sites

Sorry for double posting, again.

Anyway I got that working (Running Scripts - Parameters) but if I use the function AutoItErrorHandler, it won't work now. I don't know what to mod or to do next.

Any help would be appreciated.

edit:

I do think it is because of the "$CmdLine" in my code and the "$CmdLineRaw".

Edited by Doll

Smile. :)

Link to comment
Share on other sites

Close... ooookay, that wasn't that simple. The AutoItErrorHandler UDF seems to be a wrapper program (nice find :) , new to me). Thus the flow is about as follows:

- if you call your 'program.exe -start' it starts AutoItErrorHandler() and idles out afterwards! AutoItErrorHandler() takes over the progress flow of this first instance, the code flow never reaches your original script.

- AutoItErrorHandler() calls your program.exe the with a commandline option '/AutoIt3ExecuteScript', which indicates the new instance NOT to run AutoItErrorHandler() again!

- this new instance of your script is NOT started with the original commandline, the original command line parsed to the first instance of the program is lost...

Heres a (dirty?) tweak for that:

Your program has to use this to read the command-line:

$CmdLineRaw_New = stringright($CmdLineRaw,StringLen($CmdLineRaw)-StringInStr($CmdLineRaw,'|'))
If @Compiled Then
    if NOT StringInStr($CmdLineRaw_New, "-start") Then
        MsgBox(0,'','Wrong CmdLine Parameters, program start canceled!' & @crlf & $CmdLineRaw_New)
        Exit
    Else
        MsgBox(0,'',$CmdLineRaw_New)
    EndIf
EndIf

In AutoItErrorHandler_UDF_NoStd.au3 replace this

Local $iPID = Run($sRunLine, @ScriptDir)

with this

$CmdLineRaw_New = StringReplace($CmdLineRaw, $sRunLine,'')
Local $iPID = Run($sRunLine & " | " & $CmdLineRaw_New, @ScriptDir)

and this

Run($sRunLine, @ScriptDir)

with this.

$CmdLineRaw_New = StringReplace($CmdLineRaw, $sRunLine,'')
Run($sRunLine & " | " & $CmdLineRaw_New, @ScriptDir)

Didn't check it for AutoItErrorHandler_UDF.au3, but taking a look it seems quiet the same, just be sure make replacements accordingly (e.g. insert ', 0, 2 + 4)' into the new Run() syntax as well, as this part is for activating stdout).

Best Regards

Edited by KaFu
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...