Page 1 of 1

Chocolatey installation?

Published: August 1, 2018 - 1:29 AM
by empbilly
Hello,

How I can make a code that executes the below command?

Code: Select all

@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

Re: Chocolatey installation?

Published: August 1, 2018 - 12:20
by agauvrit
A better way would be to download install.ps1 file and execute it locally instead of downloading it every time

Code: Select all

run(r"%systemroot%\System32\WindowsPowerShell\v1.0\powershell -NoProfile -ExecutionPolicy Bypass -Command ./install.ps1")

Re: Chocolatey installation?

Published: August 2, 2018 - 4:19 PM
by empbilly
Thanks @agauvrit!! :)

Code: Select all

# -*- coding: utf-8 -*-
from setuphelpers import *

uninstallkey = []

def install():
    print("Instalando Chocolatey...")
    try:
        filecopyto('install.ps1','c:\\')
        run(r"%systemroot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command c:\install.ps1; SET 'PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin'")
    except (RuntimeError, TypeError, NameError):
        print("Erro na instalação do Chocolatey")
    print("Chocolatey instalado com sucesso!")

def uninstall():
    print("Desinstalando o Chocolatey...")
    try:
        remove_tree(ur'%allusersprofile%\chocolatey')
    except (RuntimeError, TypeError, NameError):
        print("Erro na desinstalação do Chocolatey")
    print("Chocolatey desinstalado com sucesso!")
The uninstall function is correct? I can pass the %allusersprofile% environment variable that way?