Skip to content

Commit

Permalink
Now chocolatey doesn't run under administrative rights by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
ferventcoder committed Jul 3, 2011
1 parent 7e02ca3 commit 7827941
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
8 changes: 6 additions & 2 deletions chocolatey/tools/chocolateyInstall/chocolatey.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ param([string]$file, [string]$arguments = $args, [switch] $elevated);
Write-Host "Elevating Permissions and running $file $arguments. This may take awhile, depending on the package.";
$psi = new-object System.Diagnostics.ProcessStartInfo $file;
$psi.Arguments = $arguments;
$psi.Verb = "runas";
#$psi.Verb = "runas";
# $psi.CreateNoWindow = $true
# $psi.RedirectStandardOutput = $true;
# $psi.RedirectStandardError = $true;
# $psi.UseShellExecute = $false;
$psi.WorkingDirectory = get-location;

$s = [System.Diagnostics.Process]::Start($psi);
Expand Down Expand Up @@ -162,7 +166,7 @@ $h2
foreach ($errorLine in $errorContents) {
Write-Host $errorLine -BackgroundColor Red -ForegroundColor White
}
throw $errorContents
throw [System.Exception] ($errorContents)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
function Sudo-Chocolatey {
param([string] $statements, [string] $exeToRun = 'powershell')

$statementsLog = "Running $statements"
if (!$statements.EndsWith(';')){$statements = $statements + ';'}
$wrappedStatements = "try{write-host $statementsLog;$statements start-sleep 6;}catch{write-error $($_.Exception.Message);start-sleep 8;}"
$wrappedStatements = $statements;
if ($exeToRun -eq 'powershell') {
$statementsLog = "Running $statements"
if (!$statements.EndsWith(';')){$statements = $statements + ';'}
$wrappedStatements = "try{write-host $statementsLog;$statements start-sleep 6;}catch{write-error $($_.Exception.Message);start-sleep 8;}"
}
@"
Elevating Permissions and running $exeToRun $wrappedStatements. This may take awhile, depending on the statements.;
"@ | Write-Host

$psi = new-object System.Diagnostics.ProcessStartInfo;
$psi.FileName = $exeToRun;
$psi.Arguments = $wrappedStatements;
if ($wrappedStatements -ne '') {
$psi.Arguments = $wrappedStatements;
}
$psi.Verb = "runas";
$psi.WorkingDirectory = get-location;

Expand Down Expand Up @@ -234,13 +239,16 @@ $installMessage = "Installing $packageName..."
if ($fileType -like 'msi') {
$msiArgs = "/i `"$file`""
if ($silentArgs -ne '') { $msiArgs = "$msiArgs $silentArgs";}
Start-Process -FilePath msiexec -ArgumentList $msiArgs -Wait
Sudo-Chocolatey "$msiArgs" msiexec
#Start-Process -FilePath msiexec -ArgumentList $msiArgs -Wait
}
if ($fileType -like 'exe') {
if ($silentArgs -ne '') {
Start-Process -FilePath $file -ArgumentList $silentArgs -Wait
Sudo-Chocolatey "$silentArgs" $file
#Start-Process -FilePath $file -ArgumentList $silentArgs -Wait
} else {
Start-Process -FilePath $file -Wait
Sudo-Chocolatey '' $file
#Start-Process -FilePath $file -Wait
}
}

Expand Down Expand Up @@ -452,4 +460,4 @@ function Get-WebFile {
}
}
$res.Close();
}
}

0 comments on commit 7827941

Please sign in to comment.