mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-07-04 12:13:51 -05:00
Compare commits
50 Commits
25.03.03
...
8782aaa74f
Author | SHA1 | Date | |
---|---|---|---|
8782aaa74f | |||
daf75a1d4a | |||
6b5db60ce7 | |||
df29188f1e | |||
a6bababb43 | |||
5514025577 | |||
c46a7eaa40 | |||
e0e8daf4e2 | |||
cf2f741408 | |||
7d0e4df4ec | |||
7e6634d99d | |||
f04b52d0db | |||
402082b376 | |||
79fb48e4df | |||
3faa3bad3d | |||
d441952e5e | |||
c0d6e0bbc7 | |||
fd4d783a04 | |||
e048097c78 | |||
4bfeacf80d | |||
80a933db8e | |||
9dd89136e8 | |||
7b273d5634 | |||
2d0e68c90f | |||
ba968d0cb3 | |||
8d34e2fa30 | |||
dcf752fdeb | |||
a839acd949 | |||
f05fece2e5 | |||
cf664bd1d3 | |||
6d88e51462 | |||
5bbc6c6a92 | |||
fdb156a450 | |||
7d90ab8660 | |||
f576d57ffc | |||
4889c1c508 | |||
ae1a9530f9 | |||
0467c3a7c8 | |||
7686e7fff4 | |||
468b7209be | |||
15c84f2a1f | |||
5b0ea0b373 | |||
e8de029483 | |||
af39f43cec | |||
5bb940d4d5 | |||
4c38768b32 | |||
6229ab6dd4 | |||
71c35eccd6 | |||
db521534bc | |||
a1188871f4 |
@ -1,6 +1,5 @@
|
|||||||
# Import the function (adjust the path according to your setup)
|
# Import the function (adjust the path according to your setup)
|
||||||
. "./functions/private/Install-WinUtilWinget.ps1"
|
. "./functions/private/Get-WinUtilWingetLatest.ps1"
|
||||||
. "./functions/private/Test-WinUtilPackageManager.ps1"
|
|
||||||
|
|
||||||
# Set up Information stream to be visible
|
# Set up Information stream to be visible
|
||||||
$InformationPreference = "Continue"
|
$InformationPreference = "Continue"
|
||||||
@ -8,7 +7,20 @@ $InformationPreference = "Continue"
|
|||||||
Write-Host "Starting Winget installation test..." -ForegroundColor Cyan
|
Write-Host "Starting Winget installation test..." -ForegroundColor Cyan
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Install-WinUtilWinget
|
# Test the function with verbose output
|
||||||
|
Write-Host "Attempting to run Get-WinUtilWingetLatest..." -ForegroundColor Cyan
|
||||||
|
Get-WinUtilWingetLatest -Verbose
|
||||||
|
|
||||||
|
# Verify Winget is working
|
||||||
|
if (Get-Command winget -ErrorAction SilentlyContinue) {
|
||||||
|
Write-Host "Success! Winget is installed and accessible." -ForegroundColor Green
|
||||||
|
|
||||||
|
# Display Winget version
|
||||||
|
Write-Host "`nWinget version:" -ForegroundColor Cyan
|
||||||
|
winget --version
|
||||||
|
} else {
|
||||||
|
Write-Host "Warning: Winget is installed but not accessible in the current session. You may need to restart your terminal." -ForegroundColor Yellow
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
Write-Host "Error occurred during testing: $($_.Exception.Message)" -ForegroundColor Red
|
Write-Host "Error occurred during testing: $($_.Exception.Message)" -ForegroundColor Red
|
||||||
Write-Host "Stack Trace:" -ForegroundColor Red
|
Write-Host "Stack Trace:" -ForegroundColor Red
|
||||||
|
@ -423,6 +423,26 @@
|
|||||||
"StartupType": "Automatic",
|
"StartupType": "Automatic",
|
||||||
"OriginalType": "Automatic"
|
"OriginalType": "Automatic"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"Name": "DoSvc",
|
||||||
|
"StartupType": "AutomaticDelayedStart",
|
||||||
|
"OriginalType": "Automatic"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "DsSvc",
|
||||||
|
"StartupType": "Manual",
|
||||||
|
"OriginalType": "Manual"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "DsmSvc",
|
||||||
|
"StartupType": "Manual",
|
||||||
|
"OriginalType": "Manual"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "DusmSvc",
|
||||||
|
"StartupType": "Automatic",
|
||||||
|
"OriginalType": "Automatic"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"Name": "EFS",
|
"Name": "EFS",
|
||||||
"StartupType": "Manual",
|
"StartupType": "Manual",
|
||||||
@ -878,6 +898,11 @@
|
|||||||
"StartupType": "Manual",
|
"StartupType": "Manual",
|
||||||
"OriginalType": "Manual"
|
"OriginalType": "Manual"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"Name": "SgrmBroker",
|
||||||
|
"StartupType": "Automatic",
|
||||||
|
"OriginalType": "Automatic"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"Name": "SharedAccess",
|
"Name": "SharedAccess",
|
||||||
"StartupType": "Manual",
|
"StartupType": "Manual",
|
||||||
@ -908,6 +933,11 @@
|
|||||||
"StartupType": "Manual",
|
"StartupType": "Manual",
|
||||||
"OriginalType": "Manual"
|
"OriginalType": "Manual"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"Name": "StateRepository",
|
||||||
|
"StartupType": "Manual",
|
||||||
|
"OriginalType": "Automatic"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"Name": "StiSvc",
|
"Name": "StiSvc",
|
||||||
"StartupType": "Manual",
|
"StartupType": "Manual",
|
||||||
@ -943,6 +973,11 @@
|
|||||||
"StartupType": "Automatic",
|
"StartupType": "Automatic",
|
||||||
"OriginalType": "Automatic"
|
"OriginalType": "Automatic"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"Name": "TextInputManagementService",
|
||||||
|
"StartupType": "Manual",
|
||||||
|
"OriginalType": "Automatic"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"Name": "Themes",
|
"Name": "Themes",
|
||||||
"StartupType": "Automatic",
|
"StartupType": "Automatic",
|
||||||
|
104
functions/private/Get-WinUtilWingetLatest.ps1
Normal file
104
functions/private/Get-WinUtilWingetLatest.ps1
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
function Get-WinUtilWingetLatest {
|
||||||
|
[CmdletBinding()]
|
||||||
|
param()
|
||||||
|
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Uses GitHub API to check for the latest release of Winget.
|
||||||
|
.DESCRIPTION
|
||||||
|
This function first attempts to update WinGet using winget itself, then falls back to manual installation if needed.
|
||||||
|
#>
|
||||||
|
$ProgressPreference = "SilentlyContinue"
|
||||||
|
$InformationPreference = 'Continue'
|
||||||
|
|
||||||
|
try {
|
||||||
|
$wingetCmd = Get-Command winget -ErrorAction Stop
|
||||||
|
Write-Information "Attempting to update WinGet using WinGet..."
|
||||||
|
$result = Start-Process -FilePath "`"$($wingetCmd.Source)`"" -ArgumentList "install -e --accept-source-agreements --accept-package-agreements Microsoft.AppInstaller" -Wait -NoNewWindow -PassThru
|
||||||
|
if ($result.ExitCode -ne 0) {
|
||||||
|
throw "WinGet update failed with exit code: $($result.ExitCode)"
|
||||||
|
}
|
||||||
|
return $true
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Information "WinGet not found or update failed. Attempting to install from Microsoft Store..."
|
||||||
|
try {
|
||||||
|
# Try to close any running WinGet processes
|
||||||
|
Get-Process -Name "DesktopAppInstaller", "winget" -ErrorAction SilentlyContinue | ForEach-Object {
|
||||||
|
Write-Information "Stopping running WinGet process..."
|
||||||
|
$_.Kill()
|
||||||
|
Start-Sleep -Seconds 2
|
||||||
|
}
|
||||||
|
|
||||||
|
# Try to load Windows Runtime assemblies more reliably
|
||||||
|
$null = [System.Runtime.WindowsRuntime.WindowsRuntimeSystemExtensions]
|
||||||
|
Add-Type -AssemblyName System.Runtime.WindowsRuntime
|
||||||
|
|
||||||
|
# Load required assemblies from Windows SDK
|
||||||
|
$null = @(
|
||||||
|
[Windows.Management.Deployment.PackageManager, Windows.Management.Deployment, ContentType = WindowsRuntime]
|
||||||
|
[Windows.Foundation.Uri, Windows.Foundation, ContentType = WindowsRuntime]
|
||||||
|
[Windows.Management.Deployment.DeploymentOptions, Windows.Management.Deployment, ContentType = WindowsRuntime]
|
||||||
|
)
|
||||||
|
|
||||||
|
# Initialize PackageManager
|
||||||
|
$packageManager = New-Object Windows.Management.Deployment.PackageManager
|
||||||
|
|
||||||
|
# Rest of the Microsoft Store installation logic
|
||||||
|
$appxPackage = "https://aka.ms/getwinget"
|
||||||
|
$uri = New-Object Windows.Foundation.Uri($appxPackage)
|
||||||
|
$deploymentOperation = $packageManager.AddPackageAsync($uri, $null, "Add")
|
||||||
|
|
||||||
|
# Add timeout check for deployment operation
|
||||||
|
$timeout = 300
|
||||||
|
$timer = [System.Diagnostics.Stopwatch]::StartNew()
|
||||||
|
|
||||||
|
while ($deploymentOperation.Status -eq 0) {
|
||||||
|
if ($timer.Elapsed.TotalSeconds -gt $timeout) {
|
||||||
|
throw "Installation timed out after $timeout seconds"
|
||||||
|
}
|
||||||
|
Start-Sleep -Milliseconds 100
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($deploymentOperation.Status -eq 1) {
|
||||||
|
Write-Information "Successfully installed WinGet from Microsoft Store"
|
||||||
|
return $true
|
||||||
|
} else {
|
||||||
|
throw "Installation failed with status: $($deploymentOperation.Status)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch [System.Management.Automation.RuntimeException] {
|
||||||
|
Write-Information "Windows Runtime components not available. Attempting manual download..."
|
||||||
|
try {
|
||||||
|
# Try to close any running WinGet processes
|
||||||
|
Get-Process -Name "DesktopAppInstaller", "winget" -ErrorAction SilentlyContinue | ForEach-Object {
|
||||||
|
Write-Information "Stopping running WinGet process..."
|
||||||
|
$_.Kill()
|
||||||
|
Start-Sleep -Seconds 2
|
||||||
|
}
|
||||||
|
|
||||||
|
# Fallback to direct download from GitHub
|
||||||
|
$apiUrl = "https://api.github.com/repos/microsoft/winget-cli/releases/latest"
|
||||||
|
$release = Invoke-RestMethod -Uri $apiUrl
|
||||||
|
$msixBundleUrl = ($release.assets | Where-Object { $_.name -like "*.msixbundle" }).browser_download_url
|
||||||
|
|
||||||
|
$tempFile = Join-Path $env:TEMP "Microsoft.DesktopAppInstaller.msixbundle"
|
||||||
|
Invoke-WebRequest -Uri $msixBundleUrl -OutFile $tempFile
|
||||||
|
|
||||||
|
Add-AppxPackage -Path $tempFile -ErrorAction Stop
|
||||||
|
Remove-Item $tempFile -Force
|
||||||
|
|
||||||
|
Write-Information "Successfully installed WinGet from GitHub release"
|
||||||
|
return $true
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Error "Failed to install WinGet: $_"
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Error "Failed to install WinGet: $_"
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -33,118 +33,18 @@ function Install-WinUtilWinget {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Attempting to install/update Winget`r"
|
# Install Winget via GitHub method.
|
||||||
try {
|
# Used part of my own script with some modification: ruxunderscore/windows-initialization
|
||||||
$wingetCmd = Get-Command winget -ErrorAction Stop
|
Write-Host "Downloading Winget and License File`r"
|
||||||
Write-Information "Attempting to update WinGet using WinGet..."
|
Get-WinUtilWingetLatest
|
||||||
$result = Start-Process -FilePath "`"$($wingetCmd.Source)`"" -ArgumentList "install -e --accept-source-agreements --accept-package-agreements Microsoft.AppInstaller" -Wait -NoNewWindow -PassThru
|
|
||||||
if ($result.ExitCode -ne 0) {
|
|
||||||
throw "WinGet update failed with exit code: $($result.ExitCode)"
|
|
||||||
}
|
|
||||||
Write-Output "Refreshing Environment Variables...`n"
|
|
||||||
$ENV:PATH = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
|
|
||||||
return
|
|
||||||
} catch {
|
|
||||||
Write-Information "WinGet not found or update failed. Attempting to install from Microsoft Store..."
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
# Try to close any running WinGet processes
|
|
||||||
Get-Process -Name "DesktopAppInstaller", "winget" -ErrorAction SilentlyContinue | ForEach-Object {
|
|
||||||
Write-Information "Stopping running WinGet process..."
|
|
||||||
$_.Kill()
|
|
||||||
Start-Sleep -Seconds 2
|
|
||||||
}
|
|
||||||
|
|
||||||
# Try to load Windows Runtime assemblies more reliably
|
|
||||||
$null = [System.Runtime.WindowsRuntime.WindowsRuntimeSystemExtensions]
|
|
||||||
Add-Type -AssemblyName System.Runtime.WindowsRuntime
|
|
||||||
|
|
||||||
# Load required assemblies from Windows SDK
|
|
||||||
$null = @(
|
|
||||||
[Windows.Management.Deployment.PackageManager, Windows.Management.Deployment, ContentType = WindowsRuntime]
|
|
||||||
[Windows.Foundation.Uri, Windows.Foundation, ContentType = WindowsRuntime]
|
|
||||||
[Windows.Management.Deployment.DeploymentOptions, Windows.Management.Deployment, ContentType = WindowsRuntime]
|
|
||||||
)
|
|
||||||
|
|
||||||
# Initialize PackageManager
|
|
||||||
$packageManager = New-Object Windows.Management.Deployment.PackageManager
|
|
||||||
|
|
||||||
# Rest of the Microsoft Store installation logic
|
|
||||||
$appxPackage = "https://aka.ms/getwinget"
|
|
||||||
$uri = New-Object Windows.Foundation.Uri($appxPackage)
|
|
||||||
$deploymentOperation = $packageManager.AddPackageAsync($uri, $null, "Add")
|
|
||||||
|
|
||||||
# Add timeout check for deployment operation
|
|
||||||
$timeout = 300
|
|
||||||
$timer = [System.Diagnostics.Stopwatch]::StartNew()
|
|
||||||
|
|
||||||
while ($deploymentOperation.Status -eq 0) {
|
|
||||||
if ($timer.Elapsed.TotalSeconds -gt $timeout) {
|
|
||||||
throw "Installation timed out after $timeout seconds"
|
|
||||||
}
|
|
||||||
Start-Sleep -Milliseconds 100
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($deploymentOperation.Status -eq 1) {
|
|
||||||
Write-Information "Successfully installed WinGet from Microsoft Store"
|
|
||||||
Write-Output "Refreshing Environment Variables...`n"
|
|
||||||
$ENV:PATH = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
throw "Installation failed with status: $($deploymentOperation.Status)"
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
Write-Information "Microsoft Store installation failed. Attempting to install from Nuget..."
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
## Nuget Method
|
|
||||||
Write-Host "Enabling NuGet and Module..."
|
Write-Host "Enabling NuGet and Module..."
|
||||||
# Enable TLS 1.2 for the PowerShell session
|
Install-PackageProvider -Name NuGet -Force
|
||||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
Install-Module -Name Microsoft.WinGet.Client -Force
|
||||||
|
# Winget only needs a refresh of the environment variables to be used.
|
||||||
# Try to register the NuGet package source if not present
|
|
||||||
if (-not (Get-PackageSource -Name "NuGet" -ErrorAction SilentlyContinue)) {
|
|
||||||
Register-PackageSource -Name "NuGet" -Location "https://www.nuget.org/api/v2" -ProviderName NuGet -Force
|
|
||||||
}
|
|
||||||
|
|
||||||
# Install NuGet provider with error handling
|
|
||||||
try {
|
|
||||||
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -Confirm:$false -ErrorAction Stop
|
|
||||||
} catch {
|
|
||||||
Write-Warning "Failed to install NuGet provider through standard method. Trying alternative approach..."
|
|
||||||
Install-PackageProvider -Name NuGet -Source "https://www.powershellgallery.com/api/v2" -Force -Confirm:$false
|
|
||||||
}
|
|
||||||
Install-Module -Name Microsoft.WinGet.Client -Confirm:$false -Force
|
|
||||||
|
|
||||||
# Check if WinGet was installed successfully through NuGet
|
|
||||||
$wingetCmd = Get-Command winget -ErrorAction Stop
|
|
||||||
Write-Information "Successfully installed WinGet through NuGet"
|
|
||||||
Write-Output "Refreshing Environment Variables...`n"
|
Write-Output "Refreshing Environment Variables...`n"
|
||||||
$ENV:PATH = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
|
$ENV:PATH = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
|
||||||
return
|
|
||||||
} catch {
|
} catch {
|
||||||
Write-Warning "NuGet installation failed. Attempting to install from GitHub..."
|
Write-Error "Failed to install Winget: $($_.Exception.Message)"
|
||||||
}
|
}
|
||||||
# GitHub fallback installation method
|
|
||||||
$releases_url = "https://api.github.com/repos/microsoft/winget-cli/releases/latest"
|
|
||||||
$asset = (Invoke-RestMethod -Uri $releases_url).assets |
|
|
||||||
Where-Object { $_.name -match "\.msixbundle$" } |
|
|
||||||
Select-Object -First 1
|
|
||||||
|
|
||||||
$download_url = $asset.browser_download_url
|
|
||||||
$output_path = Join-Path $env:TEMP $asset.name
|
|
||||||
|
|
||||||
Invoke-WebRequest -Uri $download_url -OutFile $output_path
|
|
||||||
Add-AppxPackage -Path $output_path -ErrorAction Stop
|
|
||||||
|
|
||||||
# Verify installation
|
|
||||||
$wingetCmd = Get-Command winget -ErrorAction Stop
|
|
||||||
Write-Information "Successfully installed WinGet through GitHub"
|
|
||||||
Write-Output "Refreshing Environment Variables...`n"
|
|
||||||
$ENV:PATH = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
|
|
||||||
return
|
|
||||||
} catch {
|
|
||||||
Write-Error "All installation methods failed. Unable to install WinGet."
|
|
||||||
throw
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user