Sign in to follow this  
Followers 0

How To Read/define Switch?

3 posts in this topic

Hi there,

Can Autoit define, read and run with switch? If yes, please advise.

Eg. I want to script that can run with switches.

install.exe /s = silent install

install.exe /L:c:\MyDocument = install to different location as define in the switch




Share this post

Link to post
Share on other sites

To define switches you can use the cmdline[] array.

cmdline[0] returns the total numbers of switches that your script is called with.

For exampe "yourscript.exe nr1 nr2 nr3 nr4" will result in

cmdline[0] = 4

cmdline[1] = nr1

cmdline[2] = nr2

cmdline[3] = nr3

cmdline[4] = nr4

if cmdline[0] = 0 then
msgbox(0, "Error", "No paramters defined!")
    if cmdline[1] = "/s" then
    ; do yoou silent install
    if cmdline[1] = "/l" then
      $install_location = cmdline[2]
     ; so your install to $install_location

To install your script to another location via this snippet use

youscript.exe /l YourLocation

Share this post

Link to post
Share on other sites

here's an example to read a variable number of commandline parameters:

$BATCH = 0
$NAME = ""
$ADDR = ""
$V_ARG = "Valid Arguments are:" & @LF & _
     "    /batch   - text to explain option." & @LF & _
     "    /install - text to explain option." & @LF & _
     "    /n NAME  - Name." & @LF & _
     "    /a Address - Address"  & @LF
For $X = 1 To $CMDLINE[0]
  $T_VAR = StringLower($CMDLINE[$X])
     Case $T_VAR = "/batch"
        $BATCH = 1
     Case $T_VAR = "/install"
        $INSTALL = 1
     Case $T_VAR = "/n"
        $X = $X + 1
        $NAME = $CMDLINE[$X]
     Case $T_VAR = "/a"
        $X = $X + 1
        $ADDR = $CMDLINE[$X]
     Case Else
        If $BATCH = 0 Then
           MsgBox( 1, "Error", "Wrong commandline argument: " & $T_VAR & @LF & $V_ARG,)

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
Live for the present,
Dream of the future,
Learn from the past.

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