mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-06-28 00:54:47 -05:00
Sacrifice to the AV Gods test 24-03-28 branch (#1766)
* Remove the Non-existing 'WPFMiscTweaksPower' found in the 'preset.json' File (#1763) * Compile Winutil * Update of Test-WinUtilPackageManager and Install-WinUtilWinget (#1757) * Updated Install-WinUtilWinget and Test-WinUtilPackageManager - Updated Test-WinUtilPackageManager to better handle the -Winget param and return a more verbose status. - Moved many of the "is installed"/"is not installed" outputs to the Test-WinUtilPackageManager function. - Changed Install-WinUtilWinget to use the GitHub install method as the primary method, and on error use the Chocolatey install method. - Updated various functions to use the Test-WinUtilPackageManager function. * Update Install-WinUtilWinget.ps1 - Changed handling of Test-WinUtilPackageManager in Install-WinUtilWinget, to prevent Test-WinUtilPackageManager from printing out to terminal twice. * Compile Winutil * Update Paint.NET Winget name. (#1758) Paint.NET's winget package name changed. * Compile Winutil * Fixed Programms names and urls and github actions (#1759) * Compile Winutil * trying to fix github actions * Update applications.json * Compile Winutil * updated winget package PaintDotNet * Compile Winutil * Update functions.Tests.ps1 * fixing typos in unittesting * fixed the issue that made pester not to work * Compile Winutil * found a bug and fixed it * Compile Winutil --------- Co-authored-by: YusufKhalifadev <YusufKhalifadev@users.noreply.github.com> * Detect free space of installation drive and compare it with the ISO size and delete temporary MicroWin files from previous runs (#1761) * Detect free space of installation drive Compare the size of the ISO file with the free space of the installation drive (or the drive containing the User files) and, if the free size is below a certain threshold, the script will throw either a warning or an error * Delete temporary files from previous runs * Add Simple Feature to keep the Service Startup upon Applying Service Tweaks, but not when Undoing it (#1760) Added a new parameter that gives freedom of control on whether to disable this feature or not, and of course the simple feature in question. The way it works is by Getting the service using its name, and see if the Startup Value of this service is equal to the default type that Windows comes with it, if not (The User has changed it in the past), then WinUtil won't change it by default (The KeepServiceStartup is true by default), this is a more desirable behaviour when compared to how it previously worked. These changes were tested by the Author of this commit, Please read the commit patches for exact details on the changes. * Compile Winutil * Sacrifice to the AV Gods Remove Self Elevation and Disable UAC --------- Co-authored-by: Mr.k <mineshtine28546271@gmail.com> Co-authored-by: ChrisTitusTech <ChrisTitusTech@users.noreply.github.com> Co-authored-by: Rux <jonathan.e.rux@ruxunderscore.com> Co-authored-by: YusufKhalifadev <yusufkhalifadev@gmail.com> Co-authored-by: YusufKhalifadev <YusufKhalifadev@users.noreply.github.com> Co-authored-by: CodingWonders <101426328+CodingWonders@users.noreply.github.com>
This commit is contained in:
@ -10,20 +10,19 @@ function Install-WinUtilChoco {
|
||||
try {
|
||||
Write-Host "Checking if Chocolatey is Installed..."
|
||||
|
||||
if((Get-Command -Name choco -ErrorAction Ignore)) {
|
||||
Write-Host "Chocolatey Already Installed"
|
||||
if((Test-WinUtilPackageManager -choco) -eq "installed") {
|
||||
return
|
||||
}
|
||||
|
||||
Write-Host "Seems Chocolatey is not installed, installing now"
|
||||
Write-Host "Seems Chocolatey is not installed, installing now."
|
||||
Set-ExecutionPolicy Bypass -Scope Process -Force; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) -ErrorAction Stop
|
||||
powershell choco feature enable -n allowGlobalConfirmation
|
||||
|
||||
}
|
||||
Catch {
|
||||
Write-Host "==========================================="
|
||||
Write-Host "-- Chocolatey failed to install ---"
|
||||
Write-Host "==========================================="
|
||||
Write-Host "===========================================" -Foregroundcolor Red
|
||||
Write-Host "-- Chocolatey failed to install ---" -Foregroundcolor Red
|
||||
Write-Host "===========================================" -Foregroundcolor Red
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,52 +7,53 @@ function Install-WinUtilWinget {
|
||||
.DESCRIPTION
|
||||
This function will download the latest version of Winget and install it. If Winget is already installed, it will do nothing.
|
||||
#>
|
||||
Try{
|
||||
Write-Host "Checking if Winget is Installed..."
|
||||
if (Test-WinUtilPackageManager -Winget) {
|
||||
# Checks if Winget executable exists and if the Windows Version is 1809 or higher
|
||||
Write-Host "Winget Already Installed"
|
||||
$isWingetInstalled = Test-WinUtilPackageManager -winget
|
||||
|
||||
Try {
|
||||
if ($isWingetInstalled -eq "installed") {
|
||||
Write-Host "`nWinget is already installed.`r" -ForegroundColor Green
|
||||
return
|
||||
} elseif ($isWingetInstalled -eq "outdated") {
|
||||
Write-Host "`nWinget is Outdated. Continuing with install.`r" -ForegroundColor Yellow
|
||||
} else {
|
||||
Write-Host "`nWinget is not Installed. Continuing with install.`r" -ForegroundColor Red
|
||||
}
|
||||
|
||||
# Gets the computer's information
|
||||
if ($null -eq $sync.ComputerInfo){
|
||||
$ComputerInfo = Get-ComputerInfo -ErrorAction Stop
|
||||
}
|
||||
Else {
|
||||
} else {
|
||||
$ComputerInfo = $sync.ComputerInfo
|
||||
}
|
||||
|
||||
if (($ComputerInfo.WindowsVersion) -lt "1809") {
|
||||
# Checks if Windows Version is too old for Winget
|
||||
Write-Host "Winget is not supported on this version of Windows (Pre-1809)"
|
||||
Write-Host "Winget is not supported on this version of Windows (Pre-1809)" -ForegroundColor Red
|
||||
return
|
||||
}
|
||||
|
||||
if((Get-Command -Name choco -ErrorAction Ignore)) {
|
||||
# Checks if Chocolatey is present (In case it didn't install properly), and installs Winget with choco, if so.
|
||||
Write-Host "Chocolatey detected. Installing Winget via Chocolatey"
|
||||
Start-Process -Verb runas -FilePath powershell.exe -ArgumentList "choco install winget-cli"
|
||||
Write-Host "Winget Installed"
|
||||
Write-Output "Refreshing Environment Variables...`n"
|
||||
$ENV:PATH = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
|
||||
# Install Winget via GitHub method.
|
||||
# Used part of my own script with some modification: ruxunderscore/windows-initialization
|
||||
Write-Host "Downloading Winget Prerequsites`n"
|
||||
Get-WinUtilWingetPrerequisites
|
||||
Write-Host "Downloading Winget and License File`r"
|
||||
Get-WinUtilWingetLatest
|
||||
Write-Host "Installing Winget w/ Prerequsites`r"
|
||||
Add-AppxProvisionedPackage -Online -PackagePath $ENV:TEMP\Microsoft.DesktopAppInstaller.msixbundle -DependencyPackagePath $ENV:TEMP\Microsoft.VCLibs.x64.Desktop.appx, $ENV:TEMP\Microsoft.UI.Xaml.x64.appx -LicensePath $ENV:TEMP\License1.xml
|
||||
Write-Host "Winget Installed" -ForegroundColor Green
|
||||
# Winget only needs a refresh of the environment variables to be used.
|
||||
Write-Output "Refreshing Environment Variables...`n"
|
||||
$ENV:PATH = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
|
||||
} Catch {
|
||||
Write-Host "Failure detected while installing via GitHub method. Continuing with Chocolatey method as fallback." -ForegroundColor Red
|
||||
# In case install fails via GitHub method.
|
||||
Try {
|
||||
Start-Process -Verb runas -FilePath powershell.exe -ArgumentList "choco install winget-cli"
|
||||
Write-Host "Winget Installed" -ForegroundColor Green
|
||||
Write-Output "Refreshing Environment Variables...`n"
|
||||
$ENV:PATH = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
|
||||
} Catch {
|
||||
throw [WingetFailedInstall]::new('Failed to install!')
|
||||
}
|
||||
Else {
|
||||
# If Chocolatey doesn't exist, it will install Winget through more manual means.
|
||||
# Used part of my own script with some modification: ruxunderscore/windows-initialization
|
||||
Write-Host "Downloading Winget Prerequsites"
|
||||
Get-WinUtilWingetPrerequisites
|
||||
Write-Host "Downloading Winget and License File"
|
||||
Get-WinUtilWingetLatest
|
||||
Write-Host "Installing Winget w/ Prerequsites"
|
||||
Add-AppxProvisionedPackage -Online -PackagePath $ENV:TEMP\Microsoft.DesktopAppInstaller.msixbundle -DependencyPackagePath $ENV:TEMP\Microsoft.VCLibs.x64.Desktop.appx, $ENV:TEMP\Microsoft.UI.Xaml.x64.appx -LicensePath $ENV:TEMP\License1.xml
|
||||
Write-Host "Winget Installed"
|
||||
# Winget only needs a refresh of the environment variables to be used.
|
||||
Write-Output "Refreshing Environment Variables...`n"
|
||||
$ENV:PATH = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
|
||||
}
|
||||
}
|
||||
Catch{
|
||||
throw [WingetFailedInstall]::new('Failed to install')
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
function Invoke-GPUCheck {
|
||||
function Invoke-WinUtilGPU {
|
||||
$gpuInfo = Get-CimInstance Win32_VideoController
|
||||
|
||||
foreach ($gpu in $gpuInfo) {
|
||||
|
@ -10,11 +10,15 @@ function Invoke-WinUtilTweaks {
|
||||
.PARAMETER undo
|
||||
Indicates whether to undo the operation contained in the checkbox
|
||||
|
||||
.PARAMETER KeepServiceStartup
|
||||
Indicates whether to override the startup of a service with the one given from WinUtil,
|
||||
or to keep the startup of said service, if it was changed by the user, or another program, from its default value.
|
||||
#>
|
||||
|
||||
param(
|
||||
$CheckBox,
|
||||
$undo = $false
|
||||
$undo = $false,
|
||||
$KeepServiceStartup = $true
|
||||
)
|
||||
|
||||
Write-Debug "Tweaks: $($CheckBox)"
|
||||
@ -32,6 +36,7 @@ function Invoke-WinUtilTweaks {
|
||||
Registry = "Value"
|
||||
ScheduledTask = "State"
|
||||
Service = "StartupType"
|
||||
OriginalService = "OriginalType"
|
||||
ScriptType = "InvokeScript"
|
||||
}
|
||||
}
|
||||
@ -42,9 +47,29 @@ function Invoke-WinUtilTweaks {
|
||||
}
|
||||
}
|
||||
if($sync.configs.tweaks.$CheckBox.service){
|
||||
Write-Debug "KeepServiceStartup is $KeepServiceStartup"
|
||||
$sync.configs.tweaks.$CheckBox.service | ForEach-Object {
|
||||
Write-Debug "$($psitem.Name) and state is $($psitem.$($values.service))"
|
||||
Set-WinUtilService -Name $psitem.Name -StartupType $psitem.$($values.Service)
|
||||
$changeservice = $true
|
||||
|
||||
# The check for !($undo) is required, without it the script will throw an error for accessing unavailable memeber, which's the 'OriginalService' Property
|
||||
if($KeepServiceStartup -AND !($undo)) {
|
||||
try {
|
||||
# Check if the service exists
|
||||
$service = Get-Service -Name $psitem.Name -ErrorAction Stop
|
||||
if(!($service.StartType.ToString() -eq $psitem.$($values.OriginalService))) {
|
||||
Write-Debug "Service $($service.Name) was changed in the past to $($service.StartType.ToString()) from it's original type of $($psitem.$($values.OriginalService)), will not change it to $($psitem.$($values.service))"
|
||||
$changeservice = $false
|
||||
}
|
||||
}
|
||||
catch [System.ServiceProcess.ServiceNotFoundException] {
|
||||
Write-Warning "Service $($psitem.Name) was not found"
|
||||
}
|
||||
}
|
||||
|
||||
if($changeservice) {
|
||||
Write-Debug "$($psitem.Name) and state is $($psitem.$($values.service))"
|
||||
Set-WinUtilService -Name $psitem.Name -StartupType $psitem.$($values.Service)
|
||||
}
|
||||
}
|
||||
}
|
||||
if($sync.configs.tweaks.$CheckBox.registry){
|
||||
@ -70,4 +95,4 @@ function Invoke-WinUtilTweaks {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,47 +17,70 @@ function Test-WinUtilPackageManager {
|
||||
[System.Management.Automation.SwitchParameter]$choco
|
||||
)
|
||||
|
||||
# Install Winget if not detected
|
||||
$wingetExists = Get-Command -Name winget -ErrorAction SilentlyContinue
|
||||
if ($wingetExists) {
|
||||
$wingetversionfull = (winget --version)
|
||||
$wingetversiontrim = $wingetversionfull.Trim('v')
|
||||
if ($wingetversiontrim.EndsWith("-preview")) {
|
||||
$wingetversiontrim = $wingetversiontrim.Trim('-preview')
|
||||
$wingetpreview = $true
|
||||
}
|
||||
$wingetVersion = [System.Version]::Parse($wingetversiontrim)
|
||||
$minimumWingetVersion = [System.Version]::new(1,2,10691) # Win 11 23H2 comes with bad winget v1.2.10691
|
||||
$wingetOutdated = $wingetVersion -le $minimumWingetVersion
|
||||
|
||||
Write-Host "Winget $wingetVersionfull"
|
||||
}
|
||||
|
||||
if (!$wingetExists -or $wingetOutdated) {
|
||||
if (!$wingetExists) {
|
||||
Write-Host "Winget not detected"
|
||||
} else {
|
||||
Write-Host "- Winget out-dated"
|
||||
}
|
||||
}
|
||||
$status = "not-installed"
|
||||
|
||||
if ($winget) {
|
||||
if ($wingetExists -and !$wingetOutdated) {
|
||||
if (!$wingetpreview) {
|
||||
Write-Host "- Winget up-to-date"
|
||||
# Install Winget if not detected
|
||||
$wingetExists = Get-Command -Name winget -ErrorAction SilentlyContinue
|
||||
|
||||
if ($wingetExists) {
|
||||
# Check Winget Version
|
||||
$wingetVersionFull = (winget --version) # Full Version without 'v'.
|
||||
|
||||
# Check if Preview Version
|
||||
if ($wingetVersionFull.Contains("-preview")) {
|
||||
$wingetVersion = $wingetVersionFull.Trim("-preview")
|
||||
$wingetPreview = $true
|
||||
} else {
|
||||
Write-Host "- Winget preview version detected. Unexptected problems may occur" -ForegroundColor Yellow
|
||||
$wingetVersion = $wingetVersionFull
|
||||
$wingetPreview = $false
|
||||
}
|
||||
return $true
|
||||
|
||||
# Check if Winget's Version is too old.
|
||||
$wingetCurrentVersion = [System.Version]::Parse($wingetVersion.Trim('v'))
|
||||
$wingetBadVersion = [System.Version]::Parse("1.2.10691") # Windows 11 (22H2) comes with v1.2.10691, which is bugged.
|
||||
$wingetOutdated = $wingetCurrentVersion -le $wingetBadVersion
|
||||
Write-Host "===========================================" -ForegroundColor Green
|
||||
Write-Host "-- Winget is installed ---" -ForegroundColor Green
|
||||
Write-Host "===========================================" -ForegroundColor Green
|
||||
Write-Host "Version: $wingetVersionFull" -ForegroundColor White
|
||||
|
||||
if (!$wingetPreview) {
|
||||
Write-Host " - Winget is a release version." -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host " - Winget is a preview version. Unexpected problems may occur." -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
if (!$wingetOutdated) {
|
||||
Write-Host " - Winget is Up to Date" -ForegroundColor Green
|
||||
$status = "installed"
|
||||
}
|
||||
else {
|
||||
Write-Host " - Winget is Out of Date" -ForegroundColor Red
|
||||
$status = "outdated"
|
||||
}
|
||||
} else {
|
||||
Write-Host "===========================================" -ForegroundColor Red
|
||||
Write-Host "-- Winget is not installed ---" -ForegroundColor Red
|
||||
Write-Host "===========================================" -ForegroundColor Red
|
||||
$status = "not-installed"
|
||||
}
|
||||
}
|
||||
|
||||
if ($choco) {
|
||||
if ((Get-Command -Name choco -ErrorAction Ignore) -and ($chocoVersion = (Get-Item "$env:ChocolateyInstall\choco.exe" -ErrorAction Ignore).VersionInfo.ProductVersion)) {
|
||||
Write-Host "Chocolatey v$chocoVersion"
|
||||
return $true
|
||||
Write-Host "===========================================" -ForegroundColor Green
|
||||
Write-Host "-- Chocolatey is installed ---" -ForegroundColor Green
|
||||
Write-Host "===========================================" -ForegroundColor Green
|
||||
Write-Host "Version: v$chocoVersion" -ForegroundColor White
|
||||
$status = "installed"
|
||||
} else {
|
||||
Write-Host "===========================================" -ForegroundColor Red
|
||||
Write-Host "-- Chocolatey is not installed ---" -ForegroundColor Red
|
||||
Write-Host "===========================================" -ForegroundColor Red
|
||||
$status = "not-installed"
|
||||
}
|
||||
}
|
||||
|
||||
return $false
|
||||
return $status
|
||||
}
|
||||
|
Reference in New Issue
Block a user