legend

Pass multiple command parameters

8 posts in this topic

If $CmdLine[0] > 0 Then
    Switch $CmdLine[1]

        Case "-s"
            start()

        case "-sh"
            starth()

        Case Else
            MsgBox(16,"Error",$CmdLine[1])
    EndSwitch
Else
    MsgBox(0, "Info", "No parameter --> exit", 1)
    Exit (0)
EndIf

The problem is, I want to be able to pass multiple parameters, so if i compile the script, and drop it into cmd, and write: c:\myfile.exe -s -sh

I want it to run both functions (start and starth). But now it's only calling one of them, and ignoring the other one.

I also need a way to get the path to a file, let's say we call it like this: c:\myfile.exe -sh -f "c:\windows\notepad.exe"

How can I get "c:\windows\notepad.exe" witch is a file we dropped into cmd, -f just means we wanna insert a file

 

Share this post


Link to post
Share on other sites



Here's one way to do it.

Global $s = False, $sh = False, $f = False, $FileName = ""
If $CmdLine[0] > 0 Then
    For $I = 1 To $CmdLine[0]
        If $CmdLine[$I] = "-s" Then $s = True
        If $CmdLine[$I] = "-sh" Then $sh = True
        If $CmdLine[$I] = "-f" Then
            $f = True
            $FileName = $CmdLine[$I + 1]
        EndIf
    Next
Else
    MsgBox(0, "Info", "No parameter --> exit", 1)
    Exit (0)
EndIf
If $s Then start()
If $sh Then starth()
If $f Then DoSomethingElse()

 


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
21 minutes ago, BrewManNH said:

Here's one way to do it.

Global $s = False, $sh = False, $f = False, $FileName = ""
If $CmdLine[0] > 0 Then
    For $I = 1 To $CmdLine[0]
        If $CmdLine[$I] = "-s" Then $s = True
        If $CmdLine[$I] = "-sh" Then $sh = True
        If $CmdLine[$I] = "-f" Then
            $f = True
            $FileName = $CmdLine[$I + 1]
        EndIf
    Next
Else
    MsgBox(0, "Info", "No parameter --> exit", 1)
    Exit (0)
EndIf
If $s Then start()
If $sh Then starth()
If $f Then DoSomethingElse()

 

thank's a lot, that helped me a lot :)

Share this post


Link to post
Share on other sites

What would be the best way to show a list in the cmd windows of available commands : /? 

I could when "/?" is called, use send, to send the information to the cmd windows, but there might be better ways I can imagine?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I did a tool that goes along with a registry modification, to right click an exe, and show its parameters, if any.

Basically it sends /? as you said, and shows you the result in a gui.

Then it allows you to write the parameters you want, and will send it to the application.

Called it ParameterTool - Check screenshot.

http://imgur.com/a/Lr5jA

Edited by careca

Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Share this post


Link to post
Share on other sites

#6 ·  Posted

how could i check if the user enters a path after the parameter -f ? 

because if you just enter: c:\commandtool.exe -f and press enter, you will get an error: 

GCcgLh7.png

Share this post


Link to post
Share on other sites

#7 ·  Posted

Check the Ubound to make sure it's 1 greater than the value of $i at the time you're checking for the -f parameter. If $i and Ubound are the same, there's no file name following it. It would be much more difficult to check to see if they included -f with no file name, and then used one of the other command line parameters.

blob.exe -f -sh -s


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

15 minutes ago, BrewManNH said:

Check the Ubound to make sure it's 1 greater than the value of $i at the time you're checking for the -f parameter. If $i and Ubound are the same, there's no file name following it. It would be much more difficult to check to see if they included -f with no file name, and then used one of the other command line parameters.

blob.exe -f -sh -s

thank's :)

Global $s = False, $f = False, $FileName = ""
If $CmdLine[0] > 0 Then
    For $I = 1 To $CmdLine[0]
        If $CmdLine[$I] = "-s" Then $s = True
        If $CmdLine[$I] = "-f" Then

            $test = UBound($CmdLine)

            if $test > 2 Then
                $f = True
                $FileName = $CmdLine[$I + 1]
            Else
                MsgBox("","","")
            Exit
            EndIf



            EndIf
    Next
Else
Exit (0)
EndIf

this way might be more correct? 

If Mod($CmdLine[0], 2) <> 0 Then Exit MsgBox(16, $sTitle, "Invalid number of parameters! has to be a multiple of 2!")
Edited by legend

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