Eggsplorer Posted October 29, 2015 Posted October 29, 2015 (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\binThis 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 October 29, 2015 by Eggsplorer
ViciousXUSMC Posted October 29, 2015 Posted October 29, 2015 Sometimes if quotes get too complicated I just use a .bat file and run the .bat file with Autoit, maybe not as clean but its a solution.#RequireAdmin FileInstall("Chocolatey.bat", @TempDir & "\Chocolatey.bat", 1) Run(@TempDir & "\Chocolatey.bat", @ScriptDir, @SW_HIDE)
Moderators JLogan3o13 Posted October 29, 2015 Moderators Posted October 29, 2015 (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 October 29, 2015 by JLogan3o13 Danp2 1 "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!
Eggsplorer Posted November 3, 2015 Author Posted November 3, 2015 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?
ViciousXUSMC Posted November 3, 2015 Posted November 3, 2015 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 .au3Good to use if you want to make things portable.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now