Eggsplorer

Installing Chocolatey via AutoIt

5 posts in this topic

#1 ·  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

Share this post


Link to post
Share on other sites



#3 ·  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
1 person likes this

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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. 

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

  • Similar Content

    • StMaSi
      By StMaSi
      I'm attempting to code a Run or RunWait command that is a little on the long side and contains multiple sets of embedded quotes (as it would be issued from a CMD prompt), but can't for the life of me figure out the containing quotes as pertains to AutoIt. Here's the one-line command as it would be issued via a CMD prompt...
      "\\AppServ\G$\Connectivity\Clients\Citrix\Receiver\14.5.0.10018\CitrixReceiver.exe" ADDLOCAL="ReceiverInside,ICA_Client,WebHelper,SSON,AM,SELFSERVICE,USB,DesktopViewer,Flash,Vd3d" ALLOWADDSTORE=A ALLOWSAVEPWD=A ENABLEPRELAUNCH=Y ENABLE_SSON=Yes STORE0="AppStore;https://receiver.domain.net/Citrix/Apps/discovery;on;AppStore" /EnableCEIP=false /includeSSON /noreboot /silent I've tried so many different combinations of surrounding quotes with Run and RunWait, I just don't understand why it's this difficult to get past this.
      Can anyone assist with this?
      Thank you.
    • WoodGrain
      By WoodGrain
      Hi guys,
      This is probably an obvious one, but I really don't use this command at all so am hoping you can spot my mistake.
      I'm running a powershell script on a schedule with the following script in a function, the function is being called in a loop, but the console process is not closing in the background and I end up with a bunch of console windows running in the background:
      Run(@comspec & ' /k PowerShell.exe -STA -NonInteractive -ExecutionPolicy ByPass -Command "& ''Z:\Powershell\365\GetNextDetails.ps1'' "', "", @SW_HIDE) Thanks!
    • FrancescoDiMuro
      By FrancescoDiMuro
      Hi guys! How are you? Hope you're fine
      I'm trying to insert a text that contains quotes in a SQLite database, and I don't know how to do.
      I tried with:
      Local $sString = "1P6AV2104'0HA04'0AA0" StringReplace($sString, "'", "''") but I didn't managed to, obtaining this error:
      --> Error:    unrecognized token: "0HA04" How can I manage to solve this problem? Thanks