Jump to content

Pass a console variable at runtime


bmw74
 Share

Recommended Posts

Is there a way that I can compile a console (CUI) script, and at execution time, pass variables to be used in the script? For example:

C:\Testscript.exe <machine> <username> <password>

When this is entered, the script will take the values of <machine>, <username> and <password>, and use them inside the script for processing.

I have looked around the forum but so far I haven't found what I need.

Thanks you!

Link to comment
Share on other sites

It's all inte the helpfile, check the page "Command Line Parameters", what you want to use is either $CmdLine or $CmdLineRaw

Awesome... I looked for functions and macros, but didn't come across this special array in the help file

Thanks for your help!

Link to comment
Share on other sites

For anyone that is interested, here is how I implemented it:

If $cmdline[0] <> 0 Then
    For $i = 1 To $cmdline[0]
        Switch $cmdline[$i]
            Case "-u"
                $username = $cmdline[$i+1]
            Case "-p"
                $password = $cmdline[$i+1]
        EndSwitch
    Next
EndIf

When you compile it, it will check for the following format:

c:\<compiled_program.exe> -u <username> -p <password>

Thanks for all the help!

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