cesinha87

Run Command Line using switches

12 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
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

Share this post


Link to post
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

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

When you're dead, you don't know you're dead - it's only difficult for those that know you. It's the same way when you're stupid...

My Scripts: SCCM UDFInclude Source with Compiled Script, Windows Firewall UDF

Share this post


Link to post
Share on other sites

Just merged your third topic. Stop posting all over the forum! :mad:


When you're dead, you don't know you're dead - it's only difficult for those that know you. It's the same way when you're stupid...

My Scripts: SCCM UDFInclude Source with Compiled Script, Windows Firewall UDF

Share this post


Link to post
Share on other sites

Sorry JLogan I am new to the forum and I didn't know where to create the topic. I really apologized

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

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

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

 


When you're dead, you don't know you're dead - it's only difficult for those that know you. It's the same way when you're stupid...

My Scripts: SCCM UDFInclude Source with Compiled Script, Windows Firewall UDF

Share this post


Link to post
Share on other sites

#10 ·  Posted

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?

Share this post


Link to post
Share on other sites

#12 ·  Posted

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

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