DavidW Posted December 6, 2016 Share Posted December 6, 2016 (edited) Hello everyone, I was wondering if there was an command/possibility which let users write their own variable for example in CMD "c:\users\johan\desktop\test.exe [54]". So that the number that the user typed will be later used in a calculation function. Thanks Edited December 6, 2016 by DavidW Link to comment Share on other sites More sharing options...
RTFC Posted December 6, 2016 Share Posted December 6, 2016 Please read the section "command line parameters" here My Contributions and Wrappers Spoiler BitMaskSudokuSolver BuildPartitionTable CodeCrypter CodeScanner DigitalDisplay Eigen4AutoIt FAT Suite HighMem MetaCodeFileLibrary OSgrid Pool RdRand SecondDesktop SimulatedAnnealing Xbase I/O Link to comment Share on other sites More sharing options...
DavidW Posted December 6, 2016 Author Share Posted December 6, 2016 (edited) 6 minutes ago, RTFC said: Please read the section "command line parameters" here Yes i have already done that, But it not answering my question (I could be wrong have low experience in autoIT) EG; Is there an possibility that i change the "1" in this line to an variable, and whenever the user( who runs the script with a random number) the variable changes to the number given, so the variable is later used for another function If $Cmdline[0]>= 1 Then Edited December 6, 2016 by DavidW Link to comment Share on other sites More sharing options...
spudw2k Posted December 6, 2016 Share Posted December 6, 2016 (edited) Sorry, little difficult to understand what you are asking...but if I understand what you are looking to accomplish, yes. Consider the following: From the help file link for running scriptsmyProg.exe param1 "This is a string parameter" 99 $CmdLine[0] ; This contains 3 parameters.$CmdLine[1] ; This contains param1.$CmdLine[2] ; This contains This is a string parameter.$CmdLine[3] ; This contains 99. Notice that each parameter has it's own index in the array. $CmdLine[0] >= 1 is a good first check as it means at least one parameter was provided. It will be up to you to verify the parameter(s) values. You could then switch the condition of the parameter you need. following the execution example above, let's switch the 3rd parameter and check for 99. If $CmdLine[0] >= 1 Then Switch $CmdLine[3] Case 99 ;Do Stuff EndSelect EndIf fuzzier, or clearer? Edited December 6, 2016 by spudw2k DavidW 1 Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
DavidW Posted December 7, 2016 Author Share Posted December 7, 2016 (edited) Thanks for the explanation, it makes a little bit more sense to me now But a question, what if i do the following script ? If $cmdline[0] = 1 Then msgbox (0, "", "cool") if $cmdline[0] = 2 Then msgbox(0, "", "niet col") EndIf EndIf and i run the following parameter MyProg.exe [2], why is the msgbox of $cmdline[0] = 1 appearing? Edited December 7, 2016 by DavidW Link to comment Share on other sites More sharing options...
DavidW Posted December 7, 2016 Author Share Posted December 7, 2016 (edited) What i want to acomplish is the example in JavaScript. So that a user inputs a number in CMD like "Myprog.exe" [number] and then for example the script will run console.log (" with the number from the parameter") var Number = prompt("Insert number between 0 and 100"); if (0<Number<50){ console.log("Low value"); }else if(50<=Number<100){ console.log("High value"); }else{ console.log("not a valid number"); } Do i have to create a loop that checks every number till for example 999? till its reachs the number given in the parameters? or is there an easier way? Edited December 7, 2016 by DavidW Link to comment Share on other sites More sharing options...
RTFC Posted December 7, 2016 Share Posted December 7, 2016 You can for example use the Switch-Case construct to check fixed value ranges: $number=12 Switch $number Case 1 to 50 msgbox(0,"number = " & $number,"Low number") Case 51 to 100 msgbox(0,"number = " & $number,"High number") case Else msgbox(0,"number = " & $number,"Invalid number") EndSwitch This also supports a sequence of specific values e.g.: Case 1, 3, 5 (do odd number action>, Case 2,4,6 <do even number action>, etc, as well as individual cases, e.g., Case 1 <do value=1 action>, Case 25 <do value=25 action>, etc. My Contributions and Wrappers Spoiler BitMaskSudokuSolver BuildPartitionTable CodeCrypter CodeScanner DigitalDisplay Eigen4AutoIt FAT Suite HighMem MetaCodeFileLibrary OSgrid Pool RdRand SecondDesktop SimulatedAnnealing Xbase I/O Link to comment Share on other sites More sharing options...
DavidW Posted December 7, 2016 Author Share Posted December 7, 2016 (edited) RTFC thanks for the reponse!, a couple of questions, already appreciate the help you've done How do i eventually connect the variable $number to an cmdline parameter? that if the user runs cmd ("myprog.exe /14") the variable $number will be changed to 14 Another question if i may ask. What if want to add another parameter and i want to be able to run the parameters through cmdline so like (Myprog.exe /par 1 (number switch), /par 2 (option to choose if its minus/ equaled by/ plus etc) Can i just create another switch ? if not could you give me a point in the right direction so i can try to figure it out? Edited December 7, 2016 by DavidW Link to comment Share on other sites More sharing options...
RTFC Posted December 7, 2016 Share Posted December 7, 2016 (edited) spudw2k already pointed you in the right direction. The following crude example checks first if at least one commandline parameter is parsed; if so, it is interpreted as a number that is checked further. It then checks if a 2nd parameter is parsed, and if so, displays it. if $cmdline[0]>0 Then $number=$cmdline[1] Switch $number Case 1 to 50 msgbox(0,"number = " & $number,"Low number") Case 51 to 100 msgbox(0,"number = " & $number,"High number") case Else msgbox(0,"number = " & $number,"Invalid number") EndSwitch EndIf if $cmdline[0]>1 Then $param2=$cmdline[2] msgbox(0,"A 2nd parameter was parsed","The second parameter is" & $param2) EndIf Of course, if the order of the parsed parameters can be flexible you'd have to create more sophisticated checking, and maybe cycle through all parameters in a For-Next loop to identifiy which is which. I'll leave you to figure that one out for yourself (but search $cmdline or $cmdlineRaw on the forums to find plenty of examples). Edited December 7, 2016 by RTFC DavidW 1 My Contributions and Wrappers Spoiler BitMaskSudokuSolver BuildPartitionTable CodeCrypter CodeScanner DigitalDisplay Eigen4AutoIt FAT Suite HighMem MetaCodeFileLibrary OSgrid Pool RdRand SecondDesktop SimulatedAnnealing Xbase I/O Link to comment Share on other sites More sharing options...
DavidW Posted December 7, 2016 Author Share Posted December 7, 2016 (edited) Thanks for the example im going to make work of it, it now makes sense to me now!! You're not gonna believe your eyes of the script im going to make !! Edited December 7, 2016 by DavidW Link to comment Share on other sites More sharing options...
SadBunny Posted December 7, 2016 Share Posted December 7, 2016 2 hours ago, DavidW said: You're not gonna believe your eyes of the script im going to make !! Make your chest but already wet. Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
DavidW Posted December 8, 2016 Author Share Posted December 8, 2016 (edited) NVM Edited December 8, 2016 by DavidW Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now