Jump to content

Recommended Posts

Posted (edited)

Hi,

I want to install chocolatey (https://chocolatey.org/) with AutoIt.

I just need to send the following command to cmd:

@powershell -NoProfile -ExecutionPolicy unrestricted -Command "(iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))) >$null 2>&1" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin

This is what I tried:

RunWait(@ComSpec & " /C " "@powershell -NoProfile -ExecutionPolicy unrestricted -Command "(iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))) >$null 2>&1" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin", "");

It didn't work propably because of the quotes.

So I tried this:

$code1 = "@powershell -NoProfile -ExecutionPolicy unrestricted -Command"
$code2 = " (iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))) >$null 2>&1"
$code3 = " && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

RunWait(@ComSpec & " /C " & $code1 & $code2 & $code3, "");

Didn't work either.

Any help?

Thanks in advance =)

Edited by Eggsplorer
  • Moderators
Posted (edited)

Or you could just change the /C to /K so the window stays open. That way you can see what the command window is returning.

Alternatively, write your Run code to the console to ensure it matches up as you would expect, like this:

$code1 = "@powershell -NoProfile -ExecutionPolicy unrestricted -Command"
$code2 = " (iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))) >$null 2>&1"
$code3 = " && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

ConsoleWrite(@ComSpec & " /C " & $code1 & $code2 & $code3 & @CRLF)
;RunWait(@ComSpec & " /C " & $code1 & $code2 & $code3, "");

If it looks as you would expect, copy it from the AutoIt console window and paste into a command line, see what you get

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!

Posted

Thanks a lot.
 I used a .bat-File but without the FileInstall.
My .bat-File is located on a server but accessing with RunWait() worked withoput problems.

Is FileInstall reccommended to avoid warning messages?

Posted

FileInstall actually includes the file inside the compiled .exe so its all self containing assuming your compiling the script and not just running it as an .au3

Good to use if you want to make things portable. 

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
×
×
  • Create New...