Jump to content

Installing Chocolatey via AutoIt


Recommended Posts

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
Link to comment
Share on other sites

  • Moderators

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!

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

×
×
  • Create New...