Test 2023 08 09 (#1004)

* Add Message confirming restore point created (#953)

* Compile Winutil

* readme update

* remove unnecessary space from property name (#965)

* Compile Winutil

* Add application (#969)

Add BCU to Utilities

* Update winget.ps1 (#979)

I just updated the script to version 3.0.0 and am pushing this out to your project too. 😊

https://github.com/asheroto/winget-install

You can use the signed version from releases if preferred.

* Compile Winutil

* Commit to fix #983

* Compile Winutil

* Disables the icons on the taskbar for: (#996)

- Chat/Teams
- Search Bar
- Task View
- Widgets

* Compile Winutil

* Add naps2 (#999)

* Compile Winutil

* Update autohotkey id (#1000)

* Compile Winutil

* fix package name (#1001)

* Compile Winutil

---------

Co-authored-by: Stephen Harris <stephen@lunamile.com>
Co-authored-by: ChrisTitusTech <ChrisTitusTech@users.noreply.github.com>
Co-authored-by: edelvarden <42596339+edelvarden@users.noreply.github.com>
Co-authored-by: Giannis Lagodimos <62063308+Giann1s@users.noreply.github.com>
Co-authored-by: asheroto <49938263+asheroto@users.noreply.github.com>
Co-authored-by: FriendlyButFire <antoguada96@gmail.com>
Co-authored-by: Padsala Tushal <57517785+padsalatushal@users.noreply.github.com>
This commit is contained in:
Chris Titus 2023-09-07 14:37:27 -05:00 committed by GitHub
parent 8e138c38d3
commit 8047393dc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 712 additions and 194 deletions

View File

@ -25,7 +25,9 @@ If you are having TLS 1.2 Issues or You cannot find or resolve `christitus.com/w
If you are still having issues try changing your DNS provider to 1.1.1.1 or 8.8.8.8
EXE Wrapper for $10 @ https://www.cttstore.com/windows-toolbox
## Support
- This project needs a ⭐️ from you. Don't forget to leave a star ⭐️.
- EXE Wrapper for $10 @ https://www.cttstore.com/windows-toolbox
## Overview
@ -84,6 +86,3 @@ Thanks a lot for spending your time helping Winutil grow. Thanks a lot! Keep roc
[![Contributors](https://contrib.rocks/image?repo=ChrisTitusTech/winutil)](https://github.com/ChrisTitusTech/winutil/graphs/contributors)
## Support
- This project needs a ⭐️ from you. Don't forget to leave a star ⭐️.
- EXE Wrapper for $10 @ https://www.cttstore.com/windows-toolbox

12
config/applications.json Normal file → Executable file
View File

@ -16,7 +16,7 @@
"choco": "audacity"
},
"WPFInstallautohotkey": {
"winget": "Lexikos.AutoHotkey",
"winget": "AutoHotkey.AutoHotkey",
"choco": "autohotkey"
},
"WPFInstallbitwarden": {
@ -31,6 +31,10 @@
"winget": "Brave.Brave",
"choco": "brave"
},
"WPFInstallbulkcrapuninstaller": {
"winget": "Klocman.BulkCrapUninstaller",
"choco": "bulk-crap-uninstaller"
},
"WPFInstallchrome": {
"winget": "Google.Chrome",
"choco": "googlechrome"
@ -195,6 +199,10 @@
"winget": "mRemoteNG.mRemoteNG",
"choco": "mremoteng"
},
"WPFInstallnaps2": {
"winget": "Cyanfish.NAPS2",
"choco": "naps2"
},
"WPFInstallnodejs": {
"winget": "OpenJS.NodeJS",
"choco": "nodejs"
@ -288,7 +296,7 @@
"choco": "treesizefree"
},
"WPFInstallttaskbar": {
"winget": "TranslucentTB.TranslucentTB",
"winget": "9PF4KZ2VN4W9",
"choco": "translucenttb"
},
"WPFInstallvisualstudio": {

View File

@ -2007,6 +2007,34 @@
"name": "EnableAeroPeek",
"value": "0",
"type": "DWord"
},
{
"path": "HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced",
"OriginalValue": "1",
"name": "TaskbarMn",
"value": "0",
"type": "DWord"
},
{
"path": "HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced",
"OriginalValue": "1",
"name": "TaskbarDa",
"value": "0",
"type": "DWord"
},
{
"path": "HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced",
"OriginalValue": "1",
"name": "ShowTaskViewButton",
"value": "0",
"type": "DWord"
},
{
"Path": "HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Search",
"OriginalValue": "1",
"name": "SearchboxTaskbarMode",
"value": "0",
"type": "DWord"
}
],
"InvokeScript": [

View File

@ -20,6 +20,13 @@ function Set-WinUtilRestorePoint {
Write-Host "An error occurred while enabling System Restore: $_"
}
# Check if the SystemRestorePointCreationFrequency value exists
$exists = Get-ItemProperty -path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore" -name "SystemRestorePointCreationFrequency" -ErrorAction SilentlyContinue
if($null -eq $exists){
write-host 'Changing system to allow multiple restore points per day'
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore" -Name "SystemRestorePointCreationFrequency" -Value "0" -Type DWord -Force -ErrorAction Stop | Out-Null
}
# Get all the restore points for the current day
$existingRestorePoints = Get-ComputerRestorePoint | Where-Object { $_.CreationTime.Date -eq (Get-Date).Date }
@ -28,5 +35,6 @@ function Set-WinUtilRestorePoint {
$description = "System Restore Point created by WinUtil"
Checkpoint-Computer -Description $description -RestorePointType "MODIFY_SETTINGS"
Write-Host -ForegroundColor Green "System Restore Point Created Successfully"
}
}

View File

@ -1,6 +1,6 @@
<#PSScriptInfo
.VERSION 2.0.2
.VERSION 3.0.0
.GUID 3b581edb-5d90-4fa1-ba15-4f2377275463
@ -8,7 +8,7 @@
.COMPANYNAME asheroto
.TAGS PowerShell Windows winget win get install installer fix script
.TAGS PowerShell Windows winget win get install installer fix script setup
.PROJECTURI https://github.com/asheroto/winget-install
@ -26,26 +26,37 @@
[Version 2.0.0] - Major refactor. Reverted to UI.Xaml 2.7.3 for stability. Adjusted script to fix install issues due to winget changes (thank you ChrisTitusTech). Added in all architecture support.
[Version 2.0.1] - Renamed repo and URL references from winget-installer to winget-install. Added extra space after the last line of output.
[Version 2.0.2] - Adjusted CheckForUpdates to include Install-Script instructions and extra spacing.
[Version 2.1.0] - Added alternate method/URL for dependencies in case the main URL is down. Fixed licensing issue when winget is installed on Server 2022.
[Version 2.1.1] - Switched primary/alternate methods. Added Cleanup function to avoid errors when cleaning up temp files. Added output of URL for alternate method. Suppressed Add-AppxProvisionedPackage output. Improved success message. Improved verbiage. Improve PS script comments. Added check if the URL is empty. Moved display of URL beneath the check.
[Version 3.0.0] - Major changes. Added OS version detection checks - detects OS version, release ID, ensures compatibility. Forces older file installation for Server 2022 to avoid issues after installing. Added DebugMode, DisableCleanup, Force. Renamed CheckForUpdates to CheckForUpdate. Improved output. Improved error handling. Improved comments. Improved code readability. Moved CheckForUpdate into function. Added PowerShellGalleryName. Renamed Get-OSVersion to Get-OSInfo. Moved architecture detection into Get-OSInfo. Renamed Get-NewestLink to Get-WingetDownloadUrl. Have Get-WingetDownloadUrl not get preview releases.
#>
<#
.SYNOPSIS
Downloads the latest version of winget, its dependencies, and installs everything. PATH variable is adjusted after installation. Reboot required after installation.
Downloads and installs the latest version of winget and its dependencies. Updates the PATH variable if needed.
.DESCRIPTION
The Install-winget function automates the process of installing the winget package manager. It downloads the latest version of winget and its required dependencies from the source. After downloading, the function installs winget and updates the PATH environment variable to include directories necessary for winget's operation.
Downloads and installs the latest version of winget and its dependencies. Updates the PATH variable if needed.
This function is designed to be straightforward and easy to use, removing the hassle of manually downloading, installing, and configuring winget. To make the newly installed winget available for use, a system reboot may be required after the execution of this function. This function should be run with administrative privileges.
This script is designed to be straightforward and easy to use, removing the hassle of manually downloading, installing, and configuring winget. To make the newly installed winget available for use, a system reboot may be required after running the script.
This function should be run with administrative privileges.
.EXAMPLE
winget-install
.PARAMETER DebugMode
Enables debug mode, which shows additional information for debugging.
.PARAMETER DisableCleanup
Disables cleanup of the script and prerequisites after installation.
.PARAMETER Force
Ensures installation of winget and its dependencies, even if already present.
.PARAMETER CheckForUpdate
Checks if there is an update available for the script.
.PARAMETER Version
Displays the version of the script.
.PARAMETER Help
Displays the help information for the script.
.PARAMETER CheckForUpdate
Checks for updates of the script.
Displays the full help information for the script.
.NOTES
Version : 2.0.2
Version : 3.0.0
Created by : asheroto
.LINK
Project Site: https://github.com/asheroto/winget-install
@ -54,35 +65,143 @@
param (
[switch]$Version,
[switch]$Help,
[switch]$CheckForUpdates
[switch]$CheckForUpdate,
[switch]$DisableCleanup,
[switch]$DebugMode,
[switch]$Force
)
# Version
$CurrentVersion = '2.0.2'
$CurrentVersion = '3.0.0'
$RepoOwner = 'asheroto'
$RepoName = 'winget-install'
$PowerShellGalleryName = 'winget-install'
# Versions
$ProgressPreference = 'SilentlyContinue' # Suppress progress bar (makes downloading super fast)
$ConfirmPreference = 'None' # Suppress confirmation prompts
# Check if -Version is specified
# Display version if -Version is specified
if ($Version.IsPresent) {
$CurrentVersion
exit 0
}
# Help
# Display full help if -Help is specified
if ($Help) {
Get-Help -Name $MyInvocation.MyCommand.Source -Full
exit 0
}
# If user runs "winget-install -Verbose", output their PS and Host info.
# Display $PSVersionTable and Get-Host if -Verbose is specified
if ($PSBoundParameters.ContainsKey('Verbose') -and $PSBoundParameters['Verbose']) {
$PSVersionTable
Get-Host
}
function Get-TempFolder {
<#
.SYNOPSIS
Gets the path of the current user's temp folder.
.DESCRIPTION
This function retrieves the path of the current user's temp folder.
.EXAMPLE
Get-TempFolder
#>
return [System.IO.Path]::GetTempPath()
}
function Get-OSInfo {
<#
.SYNOPSIS
Retrieves detailed information about the operating system version and architecture.
.DESCRIPTION
This function queries both the Windows registry and the Win32_OperatingSystem class to gather comprehensive information about the operating system. It returns details such as the release ID, display version, name, type (Workstation/Server), numeric version, edition ID, version (object that includes major, minor, and build numbers), and architecture (OS architecture, not processor architecture).
.EXAMPLE
Get-OSInfo
This example retrieves the OS version details of the current system and returns an object with properties like ReleaseId, DisplayVersion, Name, Type, NumericVersion, EditionId, Version, and Architecture.
.EXAMPLE
(Get-OSInfo).Version.Major
This example retrieves the major version number of the operating system. The Get-OSInfo function returns an object with a Version property, which itself is an object containing Major, Minor, and Build properties. You can access these sub-properties using dot notation.
.EXAMPLE
$osDetails = Get-OSInfo
Write-Output "OS Name: $($osDetails.Name)"
Write-Output "OS Type: $($osDetails.Type)"
Write-Output "OS Architecture: $($osDetails.Architecture)"
This example stores the result of Get-OSInfo in a variable and then accesses various properties to print details about the operating system.
#>
[CmdletBinding()]
param ()
try {
# Get registry values
$registryValues = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
$releaseIdValue = $registryValues.ReleaseId
$displayVersionValue = $registryValues.DisplayVersion
$nameValue = $registryValues.ProductName
$editionIdValue = $registryValues.EditionId
# Strip out "Server" from the $editionIdValue if it exists
$editionIdValue = $editionIdValue -replace "Server", ""
# Get OS details using Get-CimInstance because the registry key for Name is not always correct with Windows 11
$osDetails = Get-CimInstance -ClassName Win32_OperatingSystem
$nameValue = $osDetails.Caption
# Get architecture details of the OS (not the processor)
$architecture = $osDetails.OSArchitecture
# If 32-bit or 64-bit replace with x32 and x64
if ($architecture -eq "32-bit") {
$architecture = "x32"
} elseif ($architecture -eq "64-bit") {
$architecture = "x64"
}
# Get OS version details (as version object)
$versionValue = [System.Environment]::OSVersion.Version
# Determine product type
# Reference: https://learn.microsoft.com/en-us/dotnet/api/microsoft.powershell.commands.producttype?view=powershellsdk-1.1.0
if ($osDetails.ProductType -eq 1) {
$typeValue = "Workstation"
} elseif ($osDetails.ProductType -eq 2 -or $osDetails.ProductType -eq 3) {
$typeValue = "Server"
} else {
$typeValue = "Unknown"
}
# Extract numerical value from Name
$numericVersion = ($nameValue -replace "[^\d]").Trim()
# Create and return custom object with the required properties
$result = [PSCustomObject]@{
ReleaseId = $releaseIdValue
DisplayVersion = $displayVersionValue
Name = $nameValue
Type = $typeValue
NumericVersion = $numericVersion
EditionId = $editionIdValue
Version = $versionValue
Architecture = $architecture
}
return $result
} catch {
Write-Error "Unable to get OS version details.`nError: $_"
exit 1
}
}
function Get-GitHubRelease {
<#
.SYNOPSIS
@ -127,14 +246,44 @@ function Get-GitHubRelease {
}
}
# Generates a section divider for easy reading of the output.
function CheckForUpdate {
param (
[string]$RepoOwner,
[string]$RepoName,
[version]$CurrentVersion,
[string]$PowerShellGalleryName
)
$Data = Get-GitHubRelease -Owner $RepoOwner -Repo $RepoName
if ($Data.LatestVersion -gt $CurrentVersion) {
Write-Output "`nA new version of $RepoName is available.`n"
Write-Output "Current version: $CurrentVersion."
Write-Output "Latest version: $($Data.LatestVersion)."
Write-Output "Published at: $($Data.PublishedDateTime).`n"
Write-Output "You can download the latest version from https://github.com/$RepoOwner/$RepoName/releases`n"
if ($PowerShellGalleryName) {
Write-Output "Or you can run the following command to update:"
Write-Output "Install-Script $PowerShellGalleryName -Force`n"
}
} else {
Write-Output "`n$RepoName is up to date.`n"
Write-Output "Current version: $CurrentVersion."
Write-Output "Latest version: $($Data.LatestVersion)."
Write-Output "Published at: $($Data.PublishedDateTime)."
Write-Output "`nRepository: https://github.com/$RepoOwner/$RepoName/releases`n"
}
exit 0
}
function Write-Section($text) {
<#
.SYNOPSIS
Prints a text block surrounded by a section divider for enhanced output readability.
.DESCRIPTION
This function takes a string input and prints it to the console, surrounded by a section divider made of hash characters. It is designed to enhance the readability of console output.
This function takes a string input and prints it to the console, surrounded by a section divider made of hash characters.
It is designed to enhance the readability of console output.
.PARAMETER text
The text to be printed within the section divider.
@ -150,29 +299,72 @@ function Write-Section($text) {
Write-Output ""
}
function Get-NewestLink($match) {
function Get-WingetDownloadUrl {
<#
.SYNOPSIS
Retrieves the download URL of the latest release asset that matches a specified pattern from the GitHub repository.
.DESCRIPTION
This function uses the GitHub API to get information about the latest release of the winget-cli repository. It then retrieves the download URL for the release asset that matches a specified pattern.
This function uses the GitHub API to get information about the latest release of the winget-cli repository.
It then retrieves the download URL for the release asset that matches a specified pattern.
.PARAMETER match
.PARAMETER Match
The pattern to match in the asset names.
.EXAMPLE
Get-NewestLink "msixbundle"
Get-WingetDownloadUrl "msixbundle"
This command retrieves the download URL for the latest release asset with a name that contains "msixbundle".
#>
[CmdletBinding()]
$uri = "https://api.github.com/repos/microsoft/winget-cli/releases/latest"
Write-Verbose "Getting information from $uri"
$get = Invoke-RestMethod -uri $uri -Method Get -ErrorAction stop
Write-Verbose "Getting latest release..."
$data = $get.assets | Where-Object name -Match $match
param (
[Parameter(Mandatory = $true)]
[string]$Match
)
$uri = "https://api.github.com/repos/microsoft/winget-cli/releases"
Write-Debug "Getting information from $uri"
$releases = Invoke-RestMethod -uri $uri -Method Get -ErrorAction stop
Write-Debug "Getting latest release..."
foreach ($release in $releases) {
if ($release.name -match "preview") {
continue
}
$data = $release.assets | Where-Object name -Match $Match
if ($data) {
return $data.browser_download_url
}
}
Write-Debug "Falling back to the latest release..."
$latestRelease = $releases | Select-Object -First 1
$data = $latestRelease.assets | Where-Object name -Match $Match
return $data.browser_download_url
}
function Get-WingetStatus {
<#
.SYNOPSIS
Checks if winget is installed.
.DESCRIPTION
This function checks if winget is installed.
.EXAMPLE
Get-WingetStatus
#>
# Check if winget is installed
$winget = Get-Command -Name winget -ErrorAction SilentlyContinue
# If winget is installed, return $true
if ($null -ne $winget) {
return $true
}
# If winget is not installed, return $false
return $false
}
function Update-PathEnvironmentVariable {
<#
@ -201,7 +393,11 @@ function Update-PathEnvironmentVariable {
# Check if the new path is already in the PATH variable
if (!$path.Contains($NewPath)) {
if ($DebugMode) {
Write-Output "Adding $NewPath to PATH variable for $Level..."
} else {
Write-Output "Adding PATH variable for $Level..."
}
# Add the new path to the PATH variable
$path = ($path + ";" + $NewPath).Split(';') | Select-Object -Unique
@ -210,7 +406,11 @@ function Update-PathEnvironmentVariable {
# Set the new PATH variable
[Environment]::SetEnvironmentVariable("PATH", $path, $Level)
} else {
if ($DebugMode) {
Write-Output "$NewPath already present in PATH variable for $Level, skipping."
} else {
Write-Output "PATH variable already present for $Level, skipping."
}
}
}
}
@ -257,6 +457,15 @@ function Handle-Error {
Write-Warning "Resources modified are in-use. Try closing Windows Terminal / PowerShell / Command Prompt and try again."
Write-Warning "If the problem persists, restart your computer."
return $ErrorRecord
} elseif ($ErrorRecord.Exception.Message -match 'Unable to connect to the remote server') {
Write-Warning "Cannot connect to the Internet to download the required files."
Write-Warning "Try running the script again and make sure you are connected to the Internet."
Write-Warning "Sometimes the nuget.org server is down, so you may need to try again later."
return $ErrorRecord
} elseif ($ErrorRecord.Exception.Message -match "The remote name could not be resolved") {
Write-Warning "Cannot connect to the Internet to download the required files."
Write-Warning "Try running the script again and make sure you are connected to the Internet."
Write-Warning "Make sure DNS is working correctly on your computer."
} else {
# For other errors, we should stop the execution and return the ErrorRecord so that the calling try/catch block throws the error
return $ErrorRecord
@ -266,141 +475,269 @@ function Handle-Error {
$ErrorActionPreference = $OriginalErrorActionPreference
}
# Check for updates
if ($CheckForUpdates) {
$Data = Get-GitHubRelease -Owner $RepoOwner -Repo $RepoName
function Cleanup {
<#
.SYNOPSIS
Deletes a file or directory specified without prompting for confirmation or displaying errors.
if ($Data.LatestVersion -gt $CurrentVersion) {
Write-Output "`nA new version of $RepoName is available.`n"
Write-Output "Current version: $CurrentVersion."
Write-Output "Latest version: $($Data.LatestVersion)."
Write-Output "Published at: $($Data.PublishedDateTime).`n"
Write-Output "You can download the latest version from https://github.com/$RepoOwner/$RepoName/releases`n"
Write-Output "Or you can run the following command to update:"
Write-Output "Install-Script winget-install -Force`n"
.DESCRIPTION
This function takes a path to a file or directory and deletes it without prompting for confirmation or displaying errors.
If the path is a directory, the function will delete the directory and all its contents.
.PARAMETER Path
The path of the file or directory to be deleted.
.PARAMETER Recurse
If the path is a directory, this switch specifies whether to delete the directory and all its contents.
.EXAMPLE
Cleanup -Path "C:\Temp"
This example deletes the directory "C:\Temp" and all its contents.
.EXAMPLE
Cleanup -Path "C:\Temp" -Recurse
This example deletes the directory "C:\Temp" and all its contents.
.EXAMPLE
Cleanup -Path "C:\Temp\file.txt"
This example deletes the file "C:\Temp\file.txt".
#>
param (
[string]$Path,
[switch]$Recurse
)
try {
if (Test-Path -Path $Path) {
if ($Recurse -and (Get-Item -Path $Path) -is [System.IO.DirectoryInfo]) {
Get-ChildItem -Path $Path -Recurse | Remove-Item -Force -Recurse
Remove-Item -Path $Path -Force -Recurse
} else {
Write-Output "`n$RepoName is up to date.`n"
Write-Output "Current version: $CurrentVersion."
Write-Output "Latest version: $($Data.LatestVersion)."
Write-Output "Published at: $($Data.PublishedDateTime)."
Write-Output "`nRepository: https://github.com/$RepoOwner/$RepoName/releases`n"
Remove-Item -Path $Path -Force
}
exit 0
}
try {
# Using temp directory for downloads
$tempFolder = [System.IO.Path]::GetTempPath()
# Determine architecture
$cpuArchitecture = (Get-CimInstance -ClassName Win32_Processor).Architecture
# 0 - x86, 9 - x64, 5 - ARM, 12 - ARM64
switch ($cpuArchitecture) {
0 { $arch = "x86" }
9 { $arch = "x64" }
5 { $arch = "arm" }
12 { $arch = "arm64" }
default { throw "Unknown CPU architecture detected." }
if ($DebugMode) {
Write-Output "Deleted: $Path"
}
########################
# VCLibs
########################
# Vars
$vcLibsVersion = "14.00"
$vcLibs = @{
url = "https://aka.ms/Microsoft.VCLibs.$arch.$($vcLibsVersion).Desktop.appx"
}
# Output
Write-Section "Downloading & installing ${arch} VCLibs..."
switch ($cpuArchitecture) {
0 { $arch = "x86" }
9 { $arch = "x64" }
5 { $arch = "arm" }
12 { $arch = "arm64" }
default { throw "Unknown CPU architecture detected." }
}
########################
# VCLibs
########################
# Vars
$vcLibsVersion = "14.00"
$vcLibs = @{
url = "https://aka.ms/Microsoft.VCLibs.$arch.$($vcLibsVersion).Desktop.appx"
}
# Output
Write-Section "Downloading & installing ${arch} VCLibs..."
Write-Output "URL: $($vcLibs.url)"
# Try to install VCLibs
try {
# Add-AppxPackage will throw an error if the app is already installed or higher version installed, so we need to catch it and continue
Add-AppxPackage $vcLibs.url -ErrorAction Stop
} catch {
$errorHandled = Handle-Error $_
if ($null -ne $errorHandled) {
throw $errorHandled
# Errors are ignored
}
$errorHandled = $null
}
########################
# UI.Xaml
########################
function Install-Prerequisite {
<#
.SYNOPSIS
Downloads and installs a prerequisite for winget.
.DESCRIPTION
This function takes a name, version, URL, alternate URL, content type, and body and downloads and installs the prerequisite.
.PARAMETER Name
The name of the prerequisite.
.PARAMETER Version
The version of the prerequisite.
.PARAMETER Url
The URL of the prerequisite.
.PARAMETER AlternateUrl
The alternate URL of the prerequisite.
.PARAMETER ContentType
The content type of the prerequisite.
.PARAMETER Body
The body of the prerequisite.
.PARAMETER NupkgVersion
The nupkg version of the prerequisite.
.PARAMETER AppxFileVersion
The appx file version of the prerequisite.
.EXAMPLE
Install-Prerequisite -Name "VCLibs" -Version "14.00" -Url "https://store.rg-adguard.net/api/GetFiles" -AlternateUrl "https://aka.ms/Microsoft.VCLibs.$arch.14.00.Desktop.appx" -ContentType "application/x-www-form-urlencoded" -Body "type=PackageFamilyName&url=Microsoft.VCLibs.140.00_8wekyb3d8bbwe&ring=RP&lang=en-US"
Where $arch is the architecture type of the current system.
#>
param (
[string]$Name,
[string]$Url,
[string]$AlternateUrl,
[string]$ContentType,
[string]$Body,
[string]$NupkgVersion,
[string]$AppxFileVersion
)
$osVersion = Get-OSInfo
$arch = $osVersion.Architecture
Write-Section "Downloading & installing ${arch} ${Name}..."
$ThrowReason = @{
Message = ""
Code = 0
}
try {
# ============================================================================ #
# Windows 10 / Server 2022 detection
# ============================================================================ #
# Function to extract domain from URL
function Get-DomainFromUrl($url) {
$uri = [System.Uri]$url
$domain = $uri.Host -replace "^www\."
return $domain
}
# If Server 2022 or Windows 10, force non-store version of VCLibs (return true)
$messageTemplate = "{OS} detected. Using {DOMAIN} version of {NAME}."
# Determine the OS-specific information
$osType = $osVersion.Type
$osNumericVersion = $osVersion.NumericVersion
if (($osType -eq "Server" -and $osNumericVersion -eq 2022) -or ($osType -eq "Workstation" -and $osNumericVersion -eq 10)) {
if ($osType -eq "Server") {
$osName = "Server 2022"
} else {
$osName = "Windows 10"
}
$domain = Get-DomainFromUrl $AlternateUrl
$ThrowReason.Message = ($messageTemplate -replace "{OS}", $osName) -replace "{NAME}", $Name -replace "{DOMAIN}", $domain
$ThrowReason.Code = 1
throw
}
# ============================================================================ #
# Primary method
# ============================================================================ #
$url = Invoke-WebRequest -Uri $Url -Method "POST" -ContentType $ContentType -Body $Body -UseBasicParsing | ForEach-Object Links | Where-Object outerHTML -match "$Name.+_${arch}__8wekyb3d8bbwe.appx" | ForEach-Object href
# If the URL is empty, try the alternate method
if ($url -eq "") {
$ThrowReason.Message = "URL is empty"
$ThrowReason.Code = 2
throw
}
Write-Output "URL: ${url}"
Write-Output "`nInstalling ${arch} ${Name}..."
Add-AppxPackage $url -ErrorAction Stop
Write-Output "`n$Name installed successfully."
} catch {
# Alternate method
try {
$url = $AlternateUrl
# Throw reason if alternate method is required
if ($ThrowReason.Code -eq 0) {
Write-Warning "Error when trying to download or install $Name. Trying alternate method..."
} else {
Write-Warning $ThrowReason.Message
}
Write-Output ""
# If the URL is empty, throw error
if ($url -eq "") {
throw "URL is empty"
}
# Specific logic for VCLibs alternate method
if ($Name -eq "VCLibs") {
if ($DebugMode) {
Write-Output "URL: $($url)`n"
}
Write-Output "Installing ${arch} ${Name}..."
Add-AppxPackage $url -ErrorAction Stop
Write-Output "`n$Name installed successfully."
}
# Specific logic for UI.Xaml
if ($Name -eq "UI.Xaml") {
$TempFolder = Get-TempFolder
# Vars
$uiXamlNupkgVersion = "2.7.3"
$uiXamlAppxFileVersion = "2.7"
$uiXaml = @{
url = "https://www.nuget.org/api/v2/package/Microsoft.UI.Xaml/$uiXamlNupkgVersion"
url = $url
appxFolder = "tools/AppX/$arch/Release/"
appxFilename = "Microsoft.UI.Xaml.$uiXamlAppxFileVersion.appx"
nupkgFilename = Join-Path -Path $tempFolder -ChildPath "Microsoft.UI.Xaml.$uiXamlNupkgVersion.nupkg"
nupkgFolder = Join-Path -Path $tempFolder -ChildPath "Microsoft.UI.Xaml.$uiXamlNupkgVersion"
appxFilename = "Microsoft.UI.Xaml.$AppxFileVersion.appx"
nupkgFilename = Join-Path -Path $TempFolder -ChildPath "Microsoft.UI.Xaml.$NupkgVersion.nupkg"
nupkgFolder = Join-Path -Path $TempFolder -ChildPath "Microsoft.UI.Xaml.$NupkgVersion"
}
# Output
Write-Section "Downloading & installing ${arch} UI.Xaml..."
Write-Output "Downloading: $($uiXaml.url)"
Write-Output "Saving as: $($uiXaml.nupkgFilename)"
# Debug
if ($DebugMode) {
$formattedDebugOutput = ($uiXaml | ConvertTo-Json -Depth 10 -Compress) -replace '\\\\', '\'
Write-Output "uiXaml:"
Write-Output $formattedDebugOutput
Write-Output ""
}
# Downloads from URL, saves as nupkg
# Downloading
Write-Output "Downloading UI.Xaml..."
if ($DebugMode) {
Write-Output "URL: $($uiXaml.url)"
}
Invoke-WebRequest -Uri $uiXaml.url -OutFile $uiXaml.nupkgFilename
# Extracts the nupkg file
Write-Output "Extracting into: $($uiXaml.nupkgFolder)`n"
Add-Type -Assembly System.IO.Compression.FileSystem
# Check if folder exists and delete if needed (will occur whether DisableCleanup is $true or $false)
Cleanup -Path $uiXaml.nupkgFolder -Recurse
# Extracts the nupkg file
Write-Output "Extracting into: $($uiXaml.nupkgFolder)`n"
Add-Type -Assembly System.IO.Compression.FileSystem
# Check if folder exists and delete if needed
if (Test-Path -Path $uiXaml.nupkgFolder) {
Remove-Item -Path $uiXaml.nupkgFolder -Recurse
# Extracting
Write-Output "Extracting...`n"
if ($DebugMode) {
Write-Output "Into folder: $($uiXaml.nupkgFolder)`n"
}
Add-Type -Assembly System.IO.Compression.FileSystem
[IO.Compression.ZipFile]::ExtractToDirectory($uiXaml.nupkgFilename, $uiXaml.nupkgFolder)
# Install XAML
Write-Output "Installing ${arch} XAML..."
# Prep for install
Write-Output "Installing ${arch} ${Name}..."
$XamlAppxFolder = Join-Path -Path $uiXaml.nupkgFolder -ChildPath $uiXaml.appxFolder
$XamlAppxPath = Join-Path -Path $XamlAppxFolder -ChildPath $uiXaml.appxFilename
Write-Output "Installing Appx Packages in: $XamlAppxFolder"
# For each appx file in the folder, try to install it
# Debugging
if ($DebugMode) { Write-Output "Installing appx Packages in: $XamlAppxFolder" }
# Install
Get-ChildItem -Path $XamlAppxPath -Filter *.appx | ForEach-Object {
try {
Write-Output "Installing Appx Package: $($_.Name)"
# Add-AppxPackage will throw an error if the app is already installed
# or a higher version is installed, so we need to catch it and continue
if ($DebugMode) { Write-Output "Installing appx Package: $($_.Name)" }
Add-AppxPackage $_.FullName -ErrorAction Stop
}
Write-Output "`nUI.Xaml installed successfully."
# Cleanup
if ($DisableCleanup -eq $false) {
if ($DebugMode) { Write-Output "" } # Extra line break for readability if DebugMode is enabled
Cleanup -Path $uiXaml.nupkgFilename
Cleanup -Path $uiXaml.nupkgFolder -Recurse $true
}
}
} catch {
# If unable to connect to remote server and Windows 10 or Server 2022, display warning message
$ShowOldVersionMessage = $False
if ($_.Exception.Message -match "Unable to connect to the remote server") {
# Determine the correct Windows caption and set $ShowOutput to $True if conditions are met
if ($osVersion.Type -eq "Workstation" -and $osVersion.NumericVersion -eq 10) {
$WindowsCaption = "Windows 10"
$ShowOldVersionMessage = $True
} elseif ($osVersion.Type -eq "Server" -and $osVersion.NumericVersion -eq 2022) {
$WindowsCaption = "Server 2022"
$ShowOldVersionMessage = $True
}
# Output the warning message if $ShowOldVersionMessage is $True, otherwise output the generic error message
if ($ShowOldVersionMessage) {
$OldVersionMessage = "There is an issue connecting to the server to download $Name. Unfortunately this is a known issue with the prerequisite server URLs - sometimes they are down. Since you're using $WindowsCaption you must use the non-store versions of the prerequisites, the prerequisites from the Windows store will not work, so you may need to try again later or install manually."
Write-Warning $OldVersionMessage
} else {
Write-Warning "Error when trying to download or install $Name. Please try again later or manually install $Name."
}
}
$errorHandled = Handle-Error $_
if ($null -ne $errorHandled) {
throw $errorHandled
@ -408,38 +745,114 @@ try {
$errorHandled = $null
}
}
}
########################
# winget
########################
# ============================================================================ #
# Initial checks
# ============================================================================ #
# Download winget
Write-Section "Downloading winget..."
# Check for updates if -CheckForUpdate is specified
if ($CheckForUpdate) {
CheckForUpdate -RepoOwner $RepoOwner -RepoName $RepoName -CurrentVersion $CurrentVersion -PowerShellGalleryName $PowerShellGalleryName
}
# Heading
Write-Output "winget-install $CurrentVersion"
# Set OS version
$osVersion = Get-OSInfo
# Set architecture type
$arch = $osVersion.Architecture
# If it's a workstation, make sure it is Windows 10+
if ($osVersion.Type -eq "Workstation" -and $osVersion.NumericVersion -lt 10) {
Write-Error "winget is only compatible with Windows 10 or greater."
exit 1
}
# If it's a workstation with Windows 10, make sure it's version 1809 or greater
if ($osVersion.Type -eq "Workstation" -and $osVersion.NumericVersion -eq 10 -and $osVersion.ReleaseId -lt 1809) {
Write-Error "winget is only compatible with Windows 10 version 1809 or greater."
exit 1
}
# If it's a server, it needs to be 2022+
if ($osVersion.Type -eq "Server" -and $osVersion.NumericVersion -lt 2022) {
Write-Error "winget is only compatible with Windows Server 2022+."
exit 1
}
# Check if winget is already installed
if (Get-WingetStatus) {
if ($Force -eq $false) {
Write-Output "winget is already installed, exiting..."
exit 0
}
}
# ============================================================================ #
# Beginning of installation process
# ============================================================================ #
try {
# ============================================================================ #
# Install prerequisites
# ============================================================================ #
# VCLibs
Install-Prerequisite -Name "VCLibs" -Version "14.00" -Url "https://store.rg-adguard.net/api/GetFiles" -AlternateUrl "https://aka.ms/Microsoft.VCLibs.$arch.14.00.Desktop.appx" -ContentType "application/x-www-form-urlencoded" -Body "type=PackageFamilyName&url=Microsoft.VCLibs.140.00_8wekyb3d8bbwe&ring=RP&lang=en-US"
# UI.Xaml
Install-Prerequisite -Name "UI.Xaml" -Version "2.7.3" -Url "https://store.rg-adguard.net/api/GetFiles" -AlternateUrl "https://www.nuget.org/api/v2/package/Microsoft.UI.Xaml/2.7.3" -ContentType "application/x-www-form-urlencoded" -Body "type=ProductId&url=9P5VK8KZB5QZ&ring=RP&lang=en-US" -NupkgVersion "2.7.3" -AppxFileVersion "2.7"
# ============================================================================ #
# Install winget
# ============================================================================ #
$TempFolder = Get-TempFolder
# Output
Write-Section "Downloading & installing winget..."
Write-Output "Retrieving download URL for winget from GitHub..."
$wingetUrl = Get-NewestLink("msixbundle")
$wingetUrl = Get-WingetDownloadUrl -Match "msixbundle"
$wingetPath = Join-Path -Path $tempFolder -ChildPath "winget.msixbundle"
$wingetLicenseUrl = Get-NewestLink("License1.xml")
$wingetLicenseUrl = Get-WingetDownloadUrl -Match "License1.xml"
$wingetLicensePath = Join-Path -Path $tempFolder -ChildPath "license1.xml"
Write-Output "`nDownloading: $wingetUrl"
# If the URL is empty, throw error
if ($wingetUrl -eq "") {
throw "URL is empty"
}
Write-Output "Downloading winget..."
if ($DebugMode) {
Write-Output "`nURL: $wingetUrl"
Write-Output "Saving as: $wingetPath"
}
Invoke-WebRequest -Uri $wingetUrl -OutFile $wingetPath
Write-Output "`nDownloading: $wingetLicenseUrl"
Write-Output "Downloading license..."
if ($DebugMode) {
Write-Output "`nURL: $wingetLicenseUrl"
Write-Output "Saving as: $wingetLicensePath"
}
Invoke-WebRequest -Uri $wingetLicenseUrl -OutFile $wingetLicensePath
# Install winget
Write-Section "Installing winget..."
Write-Output "`nInstalling winget..."
# Debugging
if ($DebugMode) {
Write-Output "wingetPath: $wingetPath"
Write-Output "wingetLicensePath: $wingetLicensePath"
}
# Try to install winget
try {
# Add-AppxPackage will throw an error if the app is already installed or higher version installed, so we need to catch it and continue
Add-AppxPackage -Path $wingetPath -ErrorAction SilentlyContinue
Add-AppxProvisionedPackage -Online -PackagePath $wingetPath -LicensePath $wingetLicensePath -ErrorAction SilentlyContinue | Out-Null
Write-Output "`nwinget installed successfully."
} catch {
$errorHandled = Handle-Error $_
if ($null -ne $errorHandled) {
@ -448,40 +861,54 @@ try {
$errorHandled = $null
}
# Cleanup
if ($DisableCleanup -eq $false) {
if ($DebugMode) { Write-Output "" } # Extra line break for readability if DebugMode is enabled
Cleanup -Path $wingetPath
Cleanup -Path $wingetLicensePath
}
# ============================================================================ #
# PATH environment variable
# ============================================================================ #
# Add the WindowsApps directory to the PATH variable
Write-Section "Checking and adding WindowsApps directory to PATH variable for current user if not present..."
$WindowsAppsPath = [IO.Path]::Combine([Environment]::GetEnvironmentVariable("LOCALAPPDATA"), "Microsoft", "WindowsApps")
Update-PathEnvironmentVariable -NewPath $WindowsAppsPath
########################
# Cleanup
########################
Write-Section "Cleaning up..."
Remove-Item -Path $uiXaml.nupkgFilename
Remove-Item -Path $uiXaml.nupkgFolder -Recurse
Remove-Item -Path $wingetPath
Remove-Item -Path $wingetLicensePath
########################
# ============================================================================ #
# Finished
########################
# ============================================================================ #
Write-Section "Installation complete!"
Write-Output "If winget doesn't work right now, you may need to restart your computer.`n"
# Timeout for 5 seconds to check winget
Write-Output "Checking if winget is installed and working..."
Start-Sleep -Seconds 3
# Check if winget is installed
if (Get-WingetStatus -eq $true) {
Write-Output "winget is installed and working now, you can go ahead and use it."
} else {
Write-Warning "winget is installed but is not detected as a command. Try using winget now. If it doesn't work, try restarting your computer."
Write-Warning "If you restart your computer and the command still isn't recognized, please read the Troubleshooting section`nof the README: https://github.com/asheroto/winget-install#troubleshooting`n"
Write-Warning "Make sure you have the latest version of the script by running this command: $PowerShellGalleryName -CheckForUpdate"
}
} catch {
########################
# ============================================================================ #
# Error handling
########################
# ============================================================================ #
Write-Section "WARNING! An error occurred during installation!"
Write-Warning "Something went wrong. If messages above don't help and the problem persists,"
Write-Warning "Please open an issue at https://github.com/$RepoOwner/$RepoName/issues`n"
Write-Warning "If messages above don't help and the problem persists, please read the Troubleshooting section`nof the README: https://github.com/asheroto/winget-install#troubleshooting"
Write-Warning "Make sure you have the latest version of the script by running this command: $PowerShellGalleryName -CheckForUpdate"
# If it's not 0x80073D02 (resources in use), show error
if ($_.Exception.Message -notmatch '0x80073D02') {
if ($DebugMode) {
Write-Warning "Line number : $($_.InvocationInfo.ScriptLineNumber)"
}
Write-Warning "Error: $($_.Exception.Message)`n"
}
}

54
winutil.ps1 Normal file → Executable file
View File

@ -10,7 +10,7 @@
Author : Chris Titus @christitustech
Runspace Author: @DeveloperDurp
GitHub : https://github.com/ChrisTitusTech
Version : 23.08.08
Version : 23.09.07
#>
Start-Transcript $ENV:TEMP\Winutil.log -Append
@ -21,7 +21,7 @@ Add-Type -AssemblyName System.Windows.Forms
# variable to sync between runspaces
$sync = [Hashtable]::Synchronized(@{})
$sync.PSScriptRoot = $PSScriptRoot
$sync.version = "23.08.08"
$sync.version = "23.09.07"
$sync.configs = @{}
$sync.ProcessRunning = $false
@ -780,6 +780,13 @@ function Set-WinUtilRestorePoint {
Write-Host "An error occurred while enabling System Restore: $_"
}
# Check if the SystemRestorePointCreationFrequency value exists
$exists = Get-ItemProperty -path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore" -name "SystemRestorePointCreationFrequency" -ErrorAction SilentlyContinue
if($null -eq $exists){
write-host 'Changing system to allow multiple restore points per day'
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore" -Name "SystemRestorePointCreationFrequency" -Value "0" -Type DWord -Force -ErrorAction Stop | Out-Null
}
# Get all the restore points for the current day
$existingRestorePoints = Get-ComputerRestorePoint | Where-Object { $_.CreationTime.Date -eq (Get-Date).Date }
@ -788,6 +795,7 @@ function Set-WinUtilRestorePoint {
$description = "System Restore Point created by WinUtil"
Checkpoint-Computer -Description $description -RestorePointType "MODIFY_SETTINGS"
Write-Host -ForegroundColor Green "System Restore Point Created Successfully"
}
}
function Set-WinUtilScheduledTask {
@ -2385,6 +2393,7 @@ $inputXML = '<Window x:Class="WinUtility.MainWindow"
<CheckBox Name="WPFInstallfoxpdf" Content="Foxit PDF" Margin="5,0"/>
<CheckBox Name="WPFInstalljoplin" Content="Joplin (FOSS Notes)" Margin="5,0"/>
<CheckBox Name="WPFInstalllibreoffice" Content="LibreOffice" Margin="5,0"/>
<CheckBox Name="WPFInstallnaps2" Content="NAPS2 (Document Scanner)" Margin="5,0"/>
<CheckBox Name="WPFInstallnotepadplus" Content="Notepad++" Margin="5,0"/>
<CheckBox Name="WPFInstallobsidian" Content="Obsidian" Margin="5,0"/>
<CheckBox Name="WPFInstallonlyoffice" Content="ONLYOffice Desktop" Margin="5,0"/>
@ -2463,6 +2472,7 @@ $inputXML = '<Window x:Class="WinUtility.MainWindow"
<CheckBox Name="WPFInstallanydesk" Content="AnyDesk" Margin="5,0"/>
<CheckBox Name="WPFInstallautohotkey" Content="AutoHotkey" Margin="5,0"/>
<CheckBox Name="WPFInstallbitwarden" Content="Bitwarden" Margin="5,0"/>
<CheckBox Name="WPFInstallbulkcrapuninstaller" Content="Bulk Crap Uninstaller" Margin="5,0"/>
<CheckBox Name="WPFInstallcpuz" Content="CPU-Z" Margin="5,0"/>
<CheckBox Name="WPFInstalldeluge" Content="Deluge" Margin="5,0"/>
<CheckBox Name="WPFInstalletcher" Content="Etcher USB Creator" Margin="5,0"/>
@ -2677,7 +2687,7 @@ $sync.configs.applications = '{
"choco": "audacity"
},
"WPFInstallautohotkey": {
"winget": "Lexikos.AutoHotkey",
"winget": "AutoHotkey.AutoHotkey",
"choco": "autohotkey"
},
"WPFInstallbitwarden": {
@ -2692,6 +2702,10 @@ $sync.configs.applications = '{
"winget": "Brave.Brave",
"choco": "brave"
},
"WPFInstallbulkcrapuninstaller": {
"winget": "Klocman.BulkCrapUninstaller",
"choco": "bulk-crap-uninstaller"
},
"WPFInstallchrome": {
"winget": "Google.Chrome",
"choco": "googlechrome"
@ -2856,6 +2870,10 @@ $sync.configs.applications = '{
"winget": "mRemoteNG.mRemoteNG",
"choco": "mremoteng"
},
"WPFInstallnaps2": {
"winget": "Cyanfish.NAPS2",
"choco": "naps2"
},
"WPFInstallnodejs": {
"winget": "OpenJS.NodeJS",
"choco": "nodejs"
@ -2949,7 +2967,7 @@ $sync.configs.applications = '{
"choco": "treesizefree"
},
"WPFInstallttaskbar": {
"winget": "TranslucentTB.TranslucentTB",
"winget": "9PF4KZ2VN4W9",
"choco": "translucenttb"
},
"WPFInstallvisualstudio": {
@ -5410,6 +5428,34 @@ $sync.configs.tweaks = '{
"name": "EnableAeroPeek",
"value": "0",
"type": "DWord"
},
{
"path": "HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced",
"OriginalValue": "1",
"name": "TaskbarMn",
"value": "0",
"type": "DWord"
},
{
"path": "HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced",
"OriginalValue": "1",
"name": "TaskbarDa",
"value": "0",
"type": "DWord"
},
{
"path": "HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced",
"OriginalValue": "1",
"name": "ShowTaskViewButton",
"value": "0",
"type": "DWord"
},
{
"Path": "HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Search",
"OriginalValue": "1",
"name": "SearchboxTaskbarMode",
"value": "0",
"type": "DWord"
}
],
"InvokeScript": [

View File

@ -307,6 +307,7 @@
<CheckBox Name="WPFInstallfoxpdf" Content="Foxit PDF" Margin="5,0"/>
<CheckBox Name="WPFInstalljoplin" Content="Joplin (FOSS Notes)" Margin="5,0"/>
<CheckBox Name="WPFInstalllibreoffice" Content="LibreOffice" Margin="5,0"/>
<CheckBox Name="WPFInstallnaps2" Content="NAPS2 (Document Scanner)" Margin="5,0"/>
<CheckBox Name="WPFInstallnotepadplus" Content="Notepad++" Margin="5,0"/>
<CheckBox Name="WPFInstallobsidian" Content="Obsidian" Margin="5,0"/>
<CheckBox Name="WPFInstallonlyoffice" Content="ONLYOffice Desktop" Margin="5,0"/>
@ -385,6 +386,7 @@
<CheckBox Name="WPFInstallanydesk" Content="AnyDesk" Margin="5,0"/>
<CheckBox Name="WPFInstallautohotkey" Content="AutoHotkey" Margin="5,0"/>
<CheckBox Name="WPFInstallbitwarden" Content="Bitwarden" Margin="5,0"/>
<CheckBox Name="WPFInstallbulkcrapuninstaller" Content="Bulk Crap Uninstaller" Margin="5,0"/>
<CheckBox Name="WPFInstallcpuz" Content="CPU-Z" Margin="5,0"/>
<CheckBox Name="WPFInstalldeluge" Content="Deluge" Margin="5,0"/>
<CheckBox Name="WPFInstalletcher" Content="Etcher USB Creator" Margin="5,0"/>