Jump to content

Run Command Line using switches


Recommended Posts

Hello everyone, I am  new to Autoit and I am trying to figure out how to run a command

The command I run in the CMD manually is:
 

C:\Program Files\McAfee\Agent\maconfig.exe -custom -prop1 "Test123" 

 

I am trying to converting that to Autoit and no success :( . I tried use the Run command and ShellExecute

$CustomProps1 Run(@comspec & ' /c "C:\Program Files\McAfee\Agent\maconfig.exe" & "-custom" & "-prop1" & "Test123")

or 

$CustomProps1 Run(@comspec & ' /c "C:\Program Files\McAfee\Agent\maconfig.exe -custom -prop1" & "Test123")

or


$CustomProps1 Run("maconfig.exe -custom -prop1 "$KeyValue"", "C:\Program Files\McAfee\Agent", @SW_HIDE)

 

I kind gave up on the ShellExucte command

 

Please any help

Edited by cesinha87
Link to comment
Share on other sites

Hello everyone, I am  new to Autoit and I am trying to figure out how to run a command

The command I run in the CMD manually is:
 

C:\Program Files\McAfee\Agent\maconfig.exe -custom -prop1 "Test123" 

 

I am trying to converting that to Autoit and no success :( . I tried different ways and didn't work, I will paste everything that I have tried , Please let me know the right way

$CustomProps1 Run(@comspec & ' /c "C:\Program Files\McAfee\Agent\maconfig.exe" & "-custom" & "-prop1" & "Test123")

or 

$CustomProps1 Run(@comspec & ' /c "C:\Program Files\McAfee\Agent\maconfig.exe -custom -prop1" & "Test123")

or

$CustomProps1 Run(@comspec & ' /c "C:\Program Files\McAfee\Agent\maconfig.exe" -custom -prop1 ' & "Test123")

or


$CustomProps1 Run("maconfig.exe -custom -prop1 "$KeyValue"", "C:\Program Files\McAfee\Agent", @SW_HIDE)

 

I kind gave up on the ShellExucte command

 

Please any help

Link to comment
Share on other sites

Hello everyone, I am  new to Autoit and I am trying to figure out how to run a command

The command I run in the CMD manually is:
 

C:\Program Files\McAfee\Agent\maconfig.exe -custom -prop1 "Test123" 

 

I am trying to converting that to Autoit and no success :( . I tried different ways and didn't work, I will paste everything that I have tried , Please let me know the right way

$CustomProps1 Run(@comspec & ' /c "C:\Program Files\McAfee\Agent\maconfig.exe" & "-custom" & "-prop1" & "Test123")

or 

$CustomProps1 Run(@comspec & ' /c "C:\Program Files\McAfee\Agent\maconfig.exe -custom -prop1" & "Test123")

or

$CustomProps1 Run(@comspec & ' /c "C:\Program Files\McAfee\Agent\maconfig.exe" -custom -prop1 ' & "Test123")

or


$CustomProps1 Run("maconfig.exe -custom -prop1 "$KeyValue"", "C:\Program Files\McAfee\Agent", @SW_HIDE)

 

I kind gave up on the ShellExucte command

 

Please any help

 

Link to comment
Share on other sites

  • Moderators

Personally, I find ShellExecute easier to read (personal preference). I would do something like this:

Local $customProps1 = @ProgramFilesDir & "\McAfee\Agent\maconfig.exe"
ShellExecute($customProps1, '-custom -prop1 "Test123"')

Or you could stick with a one-liner using Run:

Run(@ProgramFilesDir & '\McAfee\Agent\maconfig.exe -custom -prop1 "Test123"')

If, as you have it, you want to run in the command line, I would suggest changing your /c to /k so the window stays open. This is also helpful for troubleshooting syntax errors.

 

Edit: I also merged your topics. Please stick to one in the future.

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Alright I had to modified in order to work. When I ran your command it attempt to run maconfig under Program Files (x86) and error prompt. Here what I ran and worked

Local $customProps1 = "C:\Program Files\McAfee\Agent\maconfig.exe"
ShellExecute($customProps1, '-custom -prop1 & "Test123"')

Here is what I am trying to accomplish. I running a Regread command before and storing on $keyvalue then I want to want the maconfig.exe in silent mode (no prompt) with the registry key value

 

Local $keyvalue = RegRead("HKEY_LOCAL_MACHINE64\SOFTWARE\Microsoft\Deployment 4", "Role")
;MsgBox(0, "", "@error = " & @error)
;MsgBox($MB_SYSTEMMODAL, "Role", $keyvalue)

Local $customProps1 = "C:\Program Files\McAfee\Agent\maconfig.exe"
ShellExecute($customProps1, '-custom -prop1 & $keyvalue ')

It didn't work

 

How can I replace "test123" for the $keyvalue 

 

 

Edited by cesinha87
Link to comment
Share on other sites

Ok...I believe I am almost there, I just can't pass the $keyvalue in the ShellExecute command. Please help

 

Local $keyvalue = RegRead("HKEY_LOCAL_MACHINE64\SOFTWARE\Microsoft\Deployment 4", "Role")
;MsgBox(0, "", "@error = " & @error)
;MsgBox($MB_SYSTEMMODAL, "Role", $keyvalue)


Local $customProps1 = "C:\Program Files\McAfee\Agent"
ShellExecute($customProps1 & "\maconfig.exe", '-custom -prop1 $keyvalue', "", "", @SW_HIDE)
ShellExecute ($customProps1 & "\cmdagent.exe", '-p', "", "", @SW_HIDE)

Edited by cesinha87
Link to comment
Share on other sites

  • Moderators

You have to do it with the & symbol to add your variable, like so:

ShellExecute($customProps1 & "\maconfig.exe", '-custom -prop1 ' & $keyvalue, "", "", @SW_HIDE)

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

I think I now why it's not working. They result of $keyvalue is a plain text and in order for the command to work the switches need to be - custom -prop1 "$keyvalue"

 

Question. How can I have the result of $keyvalue and add between the quotes?

Link to comment
Share on other sites

Your way is cleaner they way I did :) . Here is what I did and it worked

 

Local $installroot = RegRead("HKEY_LOCAL_MACHINE64\SOFTWARE\Wow6432Node\McAfee\Agent", "InstallRoot")
;MsgBox($MB_SYSTEMMODAL, "Directory is", $installroot)


Local $keyvalue = RegRead("HKEY_LOCAL_MACHINE64\SOFTWARE\Microsoft\Deployment 4", "THD Role")
;MsgBox(0, "", "@error = " & @error)
;MsgBox($MB_SYSTEMMODAL, "THD Role", $keyvalue)

Local $customProps1 = $installroot
ShellExecute($customProps1 & "maconfig.exe", '-custom -prop1 ' & '"' & $keyvalue & '"', "", "", @SW_HIDE)
ShellExecute ($customProps1 & "cmdagent.exe", '-p', "", "", @SW_HIDE)

 

 

Thank you all for the help, could not have done without your guys 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...