Skip to content

Commit

Permalink
Improve script break functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
asheroto committed Nov 7, 2024
1 parent e5ce369 commit 909e8ff
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![winget-install screenshot](https://github.com/user-attachments/assets/a0019f96-dae6-4ca5-83b4-6caa10d83294)
![winget-install screenshot](https://github.com/user-attachments/assets/a30f6771-1a72-4b39-a9fb-f523802e1b79)

[![PowerShell Gallery Downloads](https://img.shields.io/powershellgallery/dt/winget-install?label=PowerShell%20Gallery%20downloads)](https://www.powershellgallery.com/packages/winget-install)
[![GitHub Downloads - All Releases](https://img.shields.io/github/downloads/asheroto/winget-install/total?label=release%20downloads)](https://github.com/asheroto/winget-install/releases)
Expand Down
52 changes: 34 additions & 18 deletions winget-install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -581,9 +581,9 @@ function ExitWithDelay {

# Exit the script with error code
if ($host.Name -eq 'ConsoleHost') {
return
Break
} else {
exit $ExitCode
Exit $ExitCode
}
}

Expand Down Expand Up @@ -753,29 +753,46 @@ function Add-ToEnvironmentPath {

function Set-PathPermissions {
param (
[string]$Path
[string]$FolderPath
)
<#
.SYNOPSIS
Sets full control permissions for the current user on the specified path.
Grants full control permissions for the Administrators group on the specified directory path.
.DESCRIPTION
This function sets full control permissions for the current user on the given directory path.
This function sets full control permissions for the Administrators group on the specified directory path.
Useful for ensuring that administrators have unrestricted access to a given folder.
.PARAMETER Path
The directory path for which to set permissions.
.PARAMETER FolderPath
The directory path for which to set full control permissions.
.EXAMPLE
Set-PathPermissions -Path "C:\Program Files\MyApp"
Set-PathPermissions -FolderPath "C:\Program Files\MyApp"
Sets full control permissions for the Administrators group on "C:\Program Files\MyApp".
#>

Write-Debug "Setting full control permissions for Administrators group on $Path."
Write-Debug "Setting full control permissions for the Administrators group on $FolderPath."

# Define the SID for the Administrators group
$administratorsGroupSid = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-32-544")
$administratorsGroup = $administratorsGroupSid.Translate([System.Security.Principal.NTAccount])
$acl = Get-Acl $Path
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($administratorsGroup, "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow")

# Retrieve the current ACL for the folder
$acl = Get-Acl -Path $FolderPath

# Define the access rule for full control inheritance
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule(
$administratorsGroup,
"FullControl",
"ContainerInherit,ObjectInherit",
"None",
"Allow"
)

# Apply the access rule to the ACL and set it on the folder
$acl.SetAccessRule($accessRule)
Set-Acl -Path $Path -AclObject $acl
Set-Acl -Path $FolderPath -AclObject $acl
}

function Test-VCRedistInstalled {
Expand Down Expand Up @@ -984,14 +1001,14 @@ if ($ForceClose) {
# Beginning of installation process
# ============================================================================ #

Write-Output ""

try {
# ============================================================================ #
# winget
# ============================================================================ #

if ($osVersion.Type -eq "Server" -and $osVersion.NumericVersion -ne 2019) {
if ($osVersion.NumericVersion -ne 2019) {

Write-Section "winget"

try {
Write-Output "Installing NuGet package provider..."
Expand Down Expand Up @@ -1142,12 +1159,11 @@ try {
Write-Debug "WinGetFolderPath: $WinGetFolderPath"

if ($null -ne $WinGetFolderPath) {
$WinGetFolderPath = $WinGetFolderPath.FullName
# Fix Permissions by adding Administrators group with FullControl
Set-PathPermissions -Path $WinGetFolderPath
Set-PathPermissions -FolderPath $WinGetFolderPathFullName

# Add Environment Path
Add-ToEnvironmentPath -PathToAdd $WinGetFolderPath
Add-ToEnvironmentPath -PathToAdd $WinGetFolderPathFullName
} else {
Write-Warning "winget folder path not found. You may need to manually add winget's folder path to your system PATH environment variable."
}
Expand Down

0 comments on commit 909e8ff

Please sign in to comment.