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

    • TheAutomator
      By TheAutomator
      A fullscreen console with custom commands!

      Introduction:
      Hi everyone!
      This funny project started as a question in the help section:
      https://www.autoitscript.com/forum/topic/174404-edit-detect-key-before-updating-content/
      I'd like to share this script with everyone that is interested. 
       
      Why would I want it?
      You like the old style fullscreen console (like in the old day's), You can add custom commands, You can customize the font a lot more compared to cmd.exe, You can share ideas or add tweaks to the script.  
      What's next?
      I'm planning to add my own programming language to it!
      Its going to be implemented with an ActiveX COM dll.
      The syntax is going to be a bit like Lua I guess, any ideas are welcome!
       
      Todo:
      Add sounds. Make an icon / logo. Design a better grammar ( Backus-Naur-vorm: https://nl.wikipedia.org/wiki/Backus-Naur-vorm ). Make test "Console-Scripts" for it. Add a file type for script files ( like batch scripts ). Clean up and modify Console.Au3 content. Add an option to have to type a login password (maybe). Call neo   
      Thanks to:
      xxaviarxx: debugging, some ideas. jguinch: debugging, adding a bunch of tweaks and ideas. kylomas: debugging, new ideas.  
      Edits and updates:
      Added tab key Main edit has focus now on startup Made a pdf that explains the upcoming programming language (need feedback about it!)  
      Until the dll is ready you can have fun with what I already have, hope you like it!
      UDF can be downloaded from the attachments.
      Regards
       
      [The programming language part is been postponed]
      [It's been a while, made a custom recursive descent parser in AutoIt, language and updates will be uploaded soon!]
       
      TheAutomator
       
      Console.au3
      ConsoleScript.pdf
    • hcI
      By hcI
      Hello I would like to know if there is a way to return a sentence in cmd when I launch from it (because I add arguments).
      For example, diskpart.exe which help to manage the key and hdd connected, when you launch it with the parameter "/f" the app return a sentence saying that it don't recognize the parameter "/f" and it return the sentence in the cmd where i started the application, not a new one.
      That's what I want to do but I couldn't find anything that would solve my problem on internet and on AutoIt like ConsoleWrite / ConsoleWriteError (don't work).
       
      Thanks
    • Duck
      By Duck
      I'm attempting to capture the output from the command line tool PSEXEC. I'm using AutoIT to run an instance of PSEXEC against a remote PC to audit Local Admins in my environment using net.exe (C:\Windows\System32> net localgroup administrators). However the usual trick I use to capture command line output does not appear to work well with PSEXEC, as the bottom portion of the output is missing from the return. Any ideas or recommendations are greatly appreciated.  
       
      Here is what I'm working with: 
      ;This script will read from a list of hosts and report who has local admin privileges on the machine #RequireAdmin Global $fileName = @ScriptDir & '\test.txt' ;hostlist, one host per line readHostList() ;Read list of hosts Func readHostList() Local $file = FileOpen($fileName, 0) While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop ConsoleWrite($line & @CRLF) ;MsgBox(0,0,$line) getLocalAdmins($line) WEnd FileClose($file) EndFunc ;run PSEXEC to list local admins Func getLocalAdmins($remotePC) Local $testFile = @ScriptDir &'\test234.txt' FileOpen($testFile, 1) Local $psexec = 'psexec \\' & $remotePC & ' net localgroup administrators' FileWriteLine($testFile, _RunCmd($psexec) ) FileClose($testFile) EndFunc ;Used to return CLI output Func _RunCmd($sCommand) Local $nPid = Run(@Comspec & " /c" & $sCommand, @SystemDir, @SW_Hide, 8), $sRet = "" If @Error then Return "ERROR:" & @ERROR ProcessWait($nPid) While 1 $sRet &= StdoutRead($nPID) If @error Or (Not ProcessExists ($nPid)) Then ExitLoop WEnd Return $sRet EndFunc  
      ## If i manually run the command on the remote PC via PSEXEC I will get the following output: 
      PsExec v2.11 - Execute processes remotely
      Copyright (C) 2001-2014 Mark Russinovich
      Sysinternals - www.sysinternals.com
      Starting net on PCNAME... on PCNAME...
      net exited on PCNAME with error code 0.
      -------------------------------------------------------------------------------
      admin
      Administrator
      Alias name     administrators
      Domain\Domain Admins
      Comment        Administrators have complete and unrestricted access to the computer/domain
      Members
      The command completed successfully.
       
      ## The returned output from running the above script is as follows:
      PsExec v2.11 - Execute processes remotely
      Copyright (C) 2001-2014 Mark Russinovich
      Sysinternals - www.sysinternals.com
      Alias name     administrators
      Connecting to PCNAME...
      Starting PSEXESVC service on PCNAME...
      Connecting with PsExec service on PCName...
      Starting net on PCNAME..
      net exited on PCNAME with error code 0.
       
      **Note to test this script PSEXEC must be in the system dir or the path in the script changed 
      PSEXEC tool: https://docs.microsoft.com/en-us/sysinternals/downloads/psexec
    • breakbadsp
      By breakbadsp
      I want to run a python script from autoit. 
      I know we can do this with shellexecute or run , but this python script takes 3 cmd line arguments.
      How to pass them from autoit script?
      I tried many ways.
      Following solution also not working 
      e.g. 
      RunWait( 'fullpath\Python.exe Scriptpath\ReadLog.py  -f "file.log" -k "key" -e "errMsg" ') Found solution:
      RunWait( 'fullpath\Python.exe ReadLog.py -f "file.log" -k "key" -e "errMsg" ', 'Working_directory_path')  
      PFB description:
      https://stackoverflow.com/questions/45757834/how-to-pass-command-line-arguments-to-a-python-script-anyscript-while-executin
       
    • TheAutomator
      By TheAutomator
      Can anyone tell me why this isn't working?..
      #include <array.au3> $regexp = StringRegExp("test 'a b c'", "'([^']|'')*'|\S+", 3) _ArrayDisplay($regexp) trying to split this "test 'a b c'  'some other '' test'' ...'" into:
      0: test
      1: 'a b c'
      2: ...
      but it gives me:
      0: test
      1: c