Jump to content

How To Read/define Switch?


Recommended Posts

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

Thanks

Regards

Daniel

Link to comment
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!")
exit
  else
    if cmdline[1] = "/s" then
    ; do yoou silent install
    endif
    if cmdline[1] = "/l" then
      $install_location = cmdline[2]
     ; so your install to $install_location
    endif
endif

To install your script to another location via this snippet use

youscript.exe /l YourLocation

Link to comment
Share on other sites

  • Developers

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

$BATCH = 0
$INSTALL=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])
  Select
     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,)
        EndIf
        Exit
  EndSelect
Next

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

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