Jump to content
Sign in to follow this  
johnmcloud

Adding Command Line Parameter

Recommended Posts

johnmcloud

Hi guys,

I don't understand how to add to a autoit .exe a command line interface The help this time don't help me like expeted.

Example simple code:

Func Test()
MsgBox(0,0,"test")
EndFunc

If i run it nothing happens, it's normal.

But how to add a command line parameter like:

C:UsersUsername>test.exe /name "True"
Completed Successfully

And see the MsgBox with the variable text?

Please provide some example

Thanks for support :oops:

Edited by johnmcloud

Share this post


Link to post
Share on other sites
water

The help file perfectly describes how passing parameters to an AutoIt exe works.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
johnmcloud

Yes, i see it but...don't understand too much :oops:

Share this post


Link to post
Share on other sites
water

Try this and you will see how it works:

MsgBox(64, "Passed Parameters", $CmdLine[0] & " parameters have been passed to this script:")
For $i = 1 To $CmdLine[0]
    MsgBox(64, "Passed Parameters", "Parameter " & $i & ": " & $CmdLine[$i])
Next
Edited by water
  • Like 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
johnmcloud

Water, two question:

1) how to do something if respect a rule, example:

test.exe /name asd --> Give me MsgBox(0,0,"asd")

test.exe asd --> Give me nothing

2) How to set a Stdout to cmd like "Complete" if not @error

Thanks :oops:

Share this post


Link to post
Share on other sites
water

Who passes the parameters to the script - a user or another script?

Only if a user passes the parameters something like "/name" makes sense.

To write something to the console you have to compile the script as CUI not as GUI (Ctrl+F7 in Scite and set "Create CUI instead of GUI EXE")


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
johnmcloud

My script don't have a GUI, select a file with FileOpenDialog and create a special shortcut with parameter. My intention was to delete that shortcut by cmd, like:

test.exe /delete test

In autoit will be:

FileDelete(@DesktopDir & "" & $var & ".ink")

The $var is equal to "test"

I don't like the CUI option, i'm not set a responce on CMD, i'll make a simpy MsgBox

Edited by johnmcloud

Share this post


Link to post
Share on other sites
water

If every parameter consists of a name (like "/name") and the value (like "asd") you could parse the parameters like this:

#AutoIt3Wrapper_Change2CUI=y
$sTitle = "Test Script"
If Mod($CmdLine[0], 2) <> 0 Then Exit MsgBox(16, $sTitle, "Invalid number of parameters! has to be a multiple of 2!")
If $CmdLine[0] = 0 Then Exit MsgBox(16, $sTitle, "No parameters passed!")
For $i = 1 To $CmdLine[0] Step 2
    If $CmdLine[$i] = "/name" Then MsgBox(64, "Passed Parameters", "/name is " & $CmdLine[$i+1])
Next
ConsoleWrite("Finished!")

Open a cmd window and enter "test.exe /name asdf".

You will get a MsgBox and the text "Finished!" on the console.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
johnmcloud

Just for know, that script write something on cmd console? Because i can't see nothing after MsgBox ( i have compiled it )

You have make this:

#AutoIt3Wrapper_Change2CUI=y

It's for write something on cmd?

Edited by johnmcloud

Share this post


Link to post
Share on other sites
water

Yes. Open a DOS console window and run your test exe with parameters "/name ads"


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
johnmcloud

mmm i don't see nothing on cmd:

Edited by johnmcloud

Share this post


Link to post
Share on other sites
water

I get the following display after clicking "OK":

C:Temp>"test.exe" /name asd

Finished!

C:Temp>


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
johnmcloud

I'm not, as you can see. I'm on Windows 7 x64, try to compile even x86 / x64, no "Finished" output, i have click ok but nothing:

C:UsersUSERNAME>"C:UsersUSERNAMEDesktopasd.exe" /name asd
C:UsersUSERNAME>
Edited by johnmcloud

Share this post


Link to post
Share on other sites
water

You have to click "OK" on the MsgBox because the text is written to the console at the end of the script.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

I can reproduce this behaviour when I removed line "#AutoIt3Wrapper_Change2CUI=y" from the script.

Make sure this line is at the top of your script and you will get "Finished!" on the console.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
johnmcloud

Nothing

Posted Image

Yes, is on top:

#AutoIt3Wrapper_Change2CUI=y
$sTitle = "Test Script"
;~ If Mod($CmdLine[0], 2) <> 0 Then Exit MsgBox(16, $sTitle, "Invalid number of parameters! has to be a multiple of 2!")
;~ If $CmdLine[0] = 0 Then Exit MsgBox(16, $sTitle, "No parameters passed!")
For $i = 1 To $CmdLine[0] Step 2
If $CmdLine[$i] = "/name" Then MsgBox(64, "Passed Parameters", "/name is " & $CmdLine[$i+1])
Next
ConsoleWrite("Finished!")
Edited by johnmcloud

Share this post


Link to post
Share on other sites
water

Did you verify that "#AutoIt3Wrapper_Change2CUI=y" is at the top of your script?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
johnmcloud

Did you verify that "#AutoIt3Wrapper_Change2CUI=y" is at the top of your script?

Yes, it's only your script, nothing else

Share this post


Link to post
Share on other sites
UEZ

Do you have the full SciTE package installed?

Btw, you don't need "#AutoIt3Wrapper_Change2CUI=y" when you don't need the CMD output!

Compile this and start the exe with some arguments:

#include <array.au3>
If $CmdLine[0] Then
_ArrayDisplay($CmdLine)
EndIf

If will display your arguments. You can analyse the arguments and do what ever you want.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
johnmcloud

UEZ, yes.

Water say that :oops: You have an alternative?

Work only in this case:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Change2CUI=y
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
$sTitle = "Test Script"
;~ If Mod($CmdLine[0], 2) <> 0 Then Exit MsgBox(16, $sTitle, "Invalid number of parameters! has to be a multiple of 2!")
;~ If $CmdLine[0] = 0 Then Exit MsgBox(16, $sTitle, "No parameters passed!")
For $i = 1 To $CmdLine[0] Step 2
    If $CmdLine[$i] = "/name" Then MsgBox(64, "Passed Parameters", "/name is " & $CmdLine[$i+1])
Next
ConsoleWrite("Finished!")

Really strange, if i enable UPX not work, If i removed requestedExecutionLevel=asInvoker not work...

I'm using 3.3.8.0 with full scite installed

Edited by johnmcloud

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  

  • Similar Content

    • nacerbaaziz
      By nacerbaaziz
      Hi dear
      With this script you can print Unicode text in the CMD screen
      the script is  easy to use
      just you  write the text that contains Unicode in the first input
      and the script automatically reflect the code in the second input
       you can copy the text to the clipboard
      or you can try printing the text in the CMD window
      I apologize to everyone for colors and shape if not appropriate
      I'm a blind man and I do not see
      Thank you for your understanding
      Greetings to all of youCmdUtM.au3
    • Simpel
      By Simpel
      Hi.
      Thanks to this post (https://www.autoitscript.com/forum/topic/189553-writing-to-cmd/?do=findComment&comment=1361142) I can now write a helpfile to the cmd when for instance passing parameter -h or -help at cmd. But then cmd is blocked by the script (I had to free it with CTRL+BREAK):
      #include <WinAPI.au3> _WinAPI_AttachConsole() $hConsole = _WinAPI_GetStdHandle(1) _WinAPI_WriteConsole($hConsole, "Print helpfile................" & @CRLF) Inside MSDN Library then I found this sentence: A process can use the FreeConsole function to detach itself from its console.
      But I don't find something like _WinAPI_FreeConsole(). How can I do it in another way?
      Regards, Conrad
    • TheAutomator
      By TheAutomator
      A fullscreen console with custom commands!

      Introduction:
      Hi everyone!
      This funny project started as a question in the help section:
      https://www.autoitscript.com/forum/topic/174404-edit-detect-key-before-updating-content/
      I'd like to share this script with everyone that is interested. 
       
      Why would I want it?
      You like the old style fullscreen console (like in the old day's), You can add custom commands, You can customize the font a lot more compared to cmd.exe, You can share ideas or add tweaks to the script.  
      Still to do:
      Write a simple custom programming language to implement this tool. Writing a little help file / pdf to describe my little programming language. Add little sound effects like a beep if there is a syntax error (optional). Clean up and modify Console.Au3 content. Add an option to have to type a login password (optional). Make an optional installer that also gives scripts for this tool a custom icon and open with command. ...Call Neo?  
      Thanks to:
      xxaviarxx: debugging, some ideas. jguinch: debugging, adding a bunch of tweaks and ideas. kylomas: debugging, new ideas.  
      Edits and updates:
      Added usage of tab key in edit control Edit has focus now on startup I'm currently rewriting a simple custom programming language to implement this tool.  
      UDF download: Console.au3
       
      Regards
      TheAutomator
    • hcI
      By hcI
      Hello I would like to know if there is a way to return a sentence in cmd when I launch from it (because I add arguments).
      For example, diskpart.exe which help to manage the key and hdd connected, when you launch it with the parameter "/f" the app return a sentence saying that it don't recognize the parameter "/f" and it return the sentence in the cmd where i started the application, not a new one.
      That's what I want to do but I couldn't find anything that would solve my problem on internet and on AutoIt like ConsoleWrite / ConsoleWriteError (don't work).
       
      Thanks
    • Duck
      By Duck
      I'm attempting to capture the output from the command line tool PSEXEC. I'm using AutoIT to run an instance of PSEXEC against a remote PC to audit Local Admins in my environment using net.exe (C:\Windows\System32> net localgroup administrators). However the usual trick I use to capture command line output does not appear to work well with PSEXEC, as the bottom portion of the output is missing from the return. Any ideas or recommendations are greatly appreciated.  
       
      Here is what I'm working with: 
      ;This script will read from a list of hosts and report who has local admin privileges on the machine #RequireAdmin Global $fileName = @ScriptDir & '\test.txt' ;hostlist, one host per line readHostList() ;Read list of hosts Func readHostList() Local $file = FileOpen($fileName, 0) While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop ConsoleWrite($line & @CRLF) ;MsgBox(0,0,$line) getLocalAdmins($line) WEnd FileClose($file) EndFunc ;run PSEXEC to list local admins Func getLocalAdmins($remotePC) Local $testFile = @ScriptDir &'\test234.txt' FileOpen($testFile, 1) Local $psexec = 'psexec \\' & $remotePC & ' net localgroup administrators' FileWriteLine($testFile, _RunCmd($psexec) ) FileClose($testFile) EndFunc ;Used to return CLI output Func _RunCmd($sCommand) Local $nPid = Run(@Comspec & " /c" & $sCommand, @SystemDir, @SW_Hide, 8), $sRet = "" If @Error then Return "ERROR:" & @ERROR ProcessWait($nPid) While 1 $sRet &= StdoutRead($nPID) If @error Or (Not ProcessExists ($nPid)) Then ExitLoop WEnd Return $sRet EndFunc  
      ## If i manually run the command on the remote PC via PSEXEC I will get the following output: 
      PsExec v2.11 - Execute processes remotely
      Copyright (C) 2001-2014 Mark Russinovich
      Sysinternals - www.sysinternals.com
      Starting net on PCNAME... on PCNAME...
      net exited on PCNAME with error code 0.
      -------------------------------------------------------------------------------
      admin
      Administrator
      Alias name     administrators
      Domain\Domain Admins
      Comment        Administrators have complete and unrestricted access to the computer/domain
      Members
      The command completed successfully.
       
      ## The returned output from running the above script is as follows:
      PsExec v2.11 - Execute processes remotely
      Copyright (C) 2001-2014 Mark Russinovich
      Sysinternals - www.sysinternals.com
      Alias name     administrators
      Connecting to PCNAME...
      Starting PSEXESVC service on PCNAME...
      Connecting with PsExec service on PCName...
      Starting net on PCNAME..
      net exited on PCNAME with error code 0.
       
      **Note to test this script PSEXEC must be in the system dir or the path in the script changed 
      PSEXEC tool: https://docs.microsoft.com/en-us/sysinternals/downloads/psexec
×