mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-07-01 10:32:35 -05:00
Compare commits
7 Commits
25.06.27
...
8b158df8c4
Author | SHA1 | Date | |
---|---|---|---|
8b158df8c4 | |||
494ad3c802 | |||
a4d1d0fd67 | |||
cb6898d835 | |||
5621b50762 | |||
b02294daf9 | |||
ae87100c61 |
@ -2430,12 +2430,6 @@
|
||||
"Order": "a001_",
|
||||
"InvokeScript": [
|
||||
"
|
||||
# Check if the user has administrative privileges
|
||||
if (-Not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
|
||||
Write-Host \"Please run this script as an administrator.\"
|
||||
return
|
||||
}
|
||||
|
||||
# Check if System Restore is enabled for the main drive
|
||||
try {
|
||||
# Try getting restore points to check if System Restore is enabled
|
||||
@ -3091,8 +3085,8 @@
|
||||
"panel": "1",
|
||||
"Order": "a002_",
|
||||
"InvokeScript": [
|
||||
"Get-ChildItem -Path \"C:\\Windows\\Temp\" *.* -Recurse | Remove-Item -Force -Recurse
|
||||
Get-ChildItem -Path $env:TEMP *.* -Recurse | Remove-Item -Force -Recurse"
|
||||
"Get-ChildItem -Path \"C:\\Windows\\Temp\" *.* -Recurse | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue
|
||||
Get-ChildItem -Path $env:TEMP *.* -Recurse | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue"
|
||||
],
|
||||
"link": "https://christitustech.github.io/winutil/dev/tweaks/Essential-Tweaks/DeleteTempFiles"
|
||||
},
|
||||
|
@ -59,8 +59,8 @@ function Invoke-WinUtilTweaks {
|
||||
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"
|
||||
} catch {
|
||||
write-host "Unable to get service $($psitem.Name)"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,11 +26,7 @@ Function Set-WinUtilService {
|
||||
|
||||
# Service exists, proceed with changing properties
|
||||
$service | Set-Service -StartupType $StartupType -ErrorAction Stop
|
||||
} catch [System.ServiceProcess.ServiceNotFoundException] {
|
||||
Write-Warning "Service $Name was not found"
|
||||
} catch {
|
||||
Write-Warning "Unable to set $Name due to unhandled exception"
|
||||
Write-Warning $_.Exception.Message
|
||||
write-host "Unable to get service $($Name)"
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -43,44 +43,48 @@ function Set-WinUtilTaskbaritem {
|
||||
[string]$description
|
||||
)
|
||||
|
||||
if ($value) {
|
||||
$sync["Form"].taskbarItemInfo.ProgressValue = $value
|
||||
}
|
||||
|
||||
if ($state) {
|
||||
switch ($state) {
|
||||
'None' { $sync["Form"].taskbarItemInfo.ProgressState = "None" }
|
||||
'Indeterminate' { $sync["Form"].taskbarItemInfo.ProgressState = "Indeterminate" }
|
||||
'Normal' { $sync["Form"].taskbarItemInfo.ProgressState = "Normal" }
|
||||
'Error' { $sync["Form"].taskbarItemInfo.ProgressState = "Error" }
|
||||
'Paused' { $sync["Form"].taskbarItemInfo.ProgressState = "Paused" }
|
||||
default { throw "[Set-WinUtilTaskbarItem] Invalid state" }
|
||||
try {
|
||||
if ($value) {
|
||||
$sync["Form"].taskbarItemInfo.ProgressValue = $value
|
||||
}
|
||||
}
|
||||
|
||||
if ($overlay) {
|
||||
switch ($overlay) {
|
||||
'logo' {
|
||||
$sync["Form"].taskbarItemInfo.Overlay = "$env:LOCALAPPDATA\winutil\cttlogo.png"
|
||||
if ($state) {
|
||||
switch ($state) {
|
||||
'None' { $sync["Form"].taskbarItemInfo.ProgressState = "None" }
|
||||
'Indeterminate' { $sync["Form"].taskbarItemInfo.ProgressState = "Indeterminate" }
|
||||
'Normal' { $sync["Form"].taskbarItemInfo.ProgressState = "Normal" }
|
||||
'Error' { $sync["Form"].taskbarItemInfo.ProgressState = "Error" }
|
||||
'Paused' { $sync["Form"].taskbarItemInfo.ProgressState = "Paused" }
|
||||
default { throw "[Set-WinUtilTaskbarItem] Invalid state" }
|
||||
}
|
||||
'checkmark' {
|
||||
$sync["Form"].taskbarItemInfo.Overlay = "$env:LOCALAPPDATA\winutil\checkmark.png"
|
||||
}
|
||||
'warning' {
|
||||
$sync["Form"].taskbarItemInfo.Overlay = "$env:LOCALAPPDATA\winutil\warning.png"
|
||||
}
|
||||
'None' {
|
||||
$sync["Form"].taskbarItemInfo.Overlay = $null
|
||||
}
|
||||
default {
|
||||
if (Test-Path $overlay) {
|
||||
$sync["Form"].taskbarItemInfo.Overlay = $overlay
|
||||
}
|
||||
|
||||
if ($overlay) {
|
||||
switch ($overlay) {
|
||||
'logo' {
|
||||
$sync["Form"].taskbarItemInfo.Overlay = "$env:LOCALAPPDATA\winutil\cttlogo.png"
|
||||
}
|
||||
'checkmark' {
|
||||
$sync["Form"].taskbarItemInfo.Overlay = "$env:LOCALAPPDATA\winutil\checkmark.png"
|
||||
}
|
||||
'warning' {
|
||||
$sync["Form"].taskbarItemInfo.Overlay = "$env:LOCALAPPDATA\winutil\warning.png"
|
||||
}
|
||||
'None' {
|
||||
$sync["Form"].taskbarItemInfo.Overlay = $null
|
||||
}
|
||||
default {
|
||||
if (Test-Path $overlay) {
|
||||
$sync["Form"].taskbarItemInfo.Overlay = $overlay
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($description) {
|
||||
$sync["Form"].taskbarItemInfo.Description = $description
|
||||
if ($description) {
|
||||
$sync["Form"].taskbarItemInfo.Description = $description
|
||||
}
|
||||
} catch {
|
||||
#do nothing
|
||||
}
|
||||
}
|
||||
|
@ -6,13 +6,21 @@ function Invoke-WPFFeatureInstall {
|
||||
|
||||
#>
|
||||
|
||||
param (
|
||||
$FeatureConfig
|
||||
)
|
||||
|
||||
if($sync.ProcessRunning) {
|
||||
$msg = "[Invoke-WPFFeatureInstall] Install process is currently running."
|
||||
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
|
||||
return
|
||||
}
|
||||
|
||||
$Features = (Get-WinUtilCheckBoxes)["WPFFeature"]
|
||||
if ($FeatureConfig) {
|
||||
$Features = $FeatureConfig
|
||||
} else {
|
||||
$Features = (Get-WinUtilCheckBoxes)["WPFFeature"]
|
||||
}
|
||||
|
||||
Invoke-WPFRunspace -ArgumentList $Features -DebugPreference $DebugPreference -ScriptBlock {
|
||||
param($Features, $DebugPreference)
|
||||
|
@ -6,14 +6,22 @@ function Invoke-WPFInstall {
|
||||
|
||||
#>
|
||||
|
||||
param (
|
||||
$InstallConfig
|
||||
)
|
||||
|
||||
if($sync.ProcessRunning) {
|
||||
$msg = "[Invoke-WPFInstall] An Install process is currently running."
|
||||
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
|
||||
return
|
||||
}
|
||||
|
||||
$PackagesToInstall = (Get-WinUtilCheckBoxes)["Install"]
|
||||
Write-Host $PackagesToInstall
|
||||
if ($InstallConfig) {
|
||||
$PackagesToInstall = $InstallConfig
|
||||
} else {
|
||||
$PackagesToInstall = (Get-WinUtilCheckBoxes)["Install"]
|
||||
}
|
||||
|
||||
if ($PackagesToInstall.Count -eq 0) {
|
||||
$WarningMsg = "Please select the program(s) to install or upgrade"
|
||||
[System.Windows.MessageBox]::Show($WarningMsg, $AppTitle, [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
|
||||
|
@ -25,24 +25,30 @@ function Invoke-WPFRunspace {
|
||||
$DebugPreference
|
||||
)
|
||||
|
||||
# Create a PowerShell instance
|
||||
$script:powershell = [powershell]::Create()
|
||||
if ($PARAM_RUN) {
|
||||
write-host "Running in Main Thread"
|
||||
& $ScriptBlock @ArgumentList @DebugPreference
|
||||
} else {
|
||||
write-host "Running in Runspace"
|
||||
# Create a PowerShell instance
|
||||
$script:powershell = [powershell]::Create()
|
||||
|
||||
# Add Scriptblock and Arguments to runspace
|
||||
$script:powershell.AddScript($ScriptBlock)
|
||||
$script:powershell.AddArgument($ArgumentList)
|
||||
$script:powershell.AddArgument($DebugPreference) # Pass DebugPreference to the script block
|
||||
$script:powershell.RunspacePool = $sync.runspace
|
||||
# Add Scriptblock and Arguments to runspace
|
||||
$script:powershell.AddScript($ScriptBlock)
|
||||
$script:powershell.AddArgument($ArgumentList)
|
||||
$script:powershell.AddArgument($DebugPreference) # Pass DebugPreference to the script block
|
||||
$script:powershell.RunspacePool = $sync.runspace
|
||||
|
||||
# Execute the RunspacePool
|
||||
$script:handle = $script:powershell.BeginInvoke()
|
||||
# Execute the RunspacePool
|
||||
$script:handle = $script:powershell.BeginInvoke()
|
||||
|
||||
# Clean up the RunspacePool threads when they are complete, and invoke the garbage collector to clean up the memory
|
||||
if ($script:handle.IsCompleted) {
|
||||
$script:powershell.EndInvoke($script:handle)
|
||||
$script:powershell.Dispose()
|
||||
$sync.runspace.Dispose()
|
||||
$sync.runspace.Close()
|
||||
[System.GC]::Collect()
|
||||
# Clean up the RunspacePool threads when they are complete, and invoke the garbage collector to clean up the memory
|
||||
if ($script:handle.IsCompleted) {
|
||||
$script:powershell.EndInvoke($script:handle)
|
||||
$script:powershell.Dispose()
|
||||
$sync.runspace.Dispose()
|
||||
$sync.runspace.Close()
|
||||
[System.GC]::Collect()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,13 +6,21 @@ function Invoke-WPFtweaksbutton {
|
||||
|
||||
#>
|
||||
|
||||
param (
|
||||
$TweaksConfig
|
||||
)
|
||||
|
||||
if($sync.ProcessRunning) {
|
||||
$msg = "[Invoke-WPFtweaksbutton] Install process is currently running."
|
||||
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
|
||||
return
|
||||
}
|
||||
|
||||
$Tweaks = (Get-WinUtilCheckBoxes)["WPFTweaks"]
|
||||
if ($TweaksConfig) {
|
||||
$Tweaks = $TweaksConfig
|
||||
} else {
|
||||
$Tweaks = (Get-WinUtilCheckBoxes)["WPFTweaks"]
|
||||
}
|
||||
|
||||
Set-WinUtilDNS -DNSProvider $sync["WPFchangedns"].text
|
||||
|
||||
|
@ -146,12 +146,60 @@ Invoke-WPFRunspace -ScriptBlock {
|
||||
} | Out-Null
|
||||
|
||||
#===========================================================================
|
||||
# Setup and Show the Form
|
||||
# Print Logo into Console
|
||||
#===========================================================================
|
||||
|
||||
# Print the logo
|
||||
Invoke-WPFFormVariables
|
||||
|
||||
#===========================================================================
|
||||
# Run Automation
|
||||
#===========================================================================
|
||||
|
||||
if ($PARAM_CONFIG) {
|
||||
if ($PARAM_RUN) {
|
||||
$installConfig = Get-Content $PARAM_CONFIG -Raw | ConvertFrom-Json
|
||||
if ($installConfig.WPFInstall) {
|
||||
write-host "Installing Programs"
|
||||
|
||||
# Create a new array to hold the combined install configurations
|
||||
$combinedInstallConfig = @()
|
||||
|
||||
# Iterate over each WPFInstall entry
|
||||
for ($i = 0; $i -lt $installConfig.WPFInstall.Count; $i++) {
|
||||
$wpfInstallEntry = $installConfig.WPFInstall[$i]
|
||||
$installEntry = $installConfig.Install[$i]
|
||||
|
||||
# Create a new object with the combined values
|
||||
$combinedEntry = @{
|
||||
Name = $wpfInstallEntry
|
||||
Winget = $installEntry.winget
|
||||
Choco = $installEntry.choco
|
||||
}
|
||||
|
||||
# Add the combined entry to the array
|
||||
$combinedInstallConfig += $combinedEntry
|
||||
}
|
||||
|
||||
# Invoke the WPFInstall function with the combined configuration
|
||||
Invoke-WPFInstall -InstallConfig $combinedInstallConfig
|
||||
}
|
||||
if ($installConfig.WPFTweaks) {
|
||||
write-host "Running Tweaks"
|
||||
Invoke-WPFtweaksbutton -TweaksConfig $installConfig.WPFTweaks
|
||||
}
|
||||
if ($installConfig.WPFFeature) {
|
||||
write-host "Installing Features"
|
||||
Invoke-WPFFeatureInstall -FeatureConfig $installConfig.WPFFeature
|
||||
}
|
||||
} else {
|
||||
Invoke-WPFImpex -type "import" -Config $PARAM_CONFIG
|
||||
}
|
||||
}
|
||||
|
||||
#===========================================================================
|
||||
# Setup and Show the Form
|
||||
#===========================================================================
|
||||
|
||||
# Progress bar in taskbaritem > Set-WinUtilProgressbar
|
||||
$sync["Form"].TaskbarItemInfo = New-Object System.Windows.Shell.TaskbarItemInfo
|
||||
Set-WinUtilTaskbaritem -state "None"
|
||||
@ -318,42 +366,6 @@ Add-Type @"
|
||||
|
||||
Invoke-WPFTab "WPFTab1BT"
|
||||
$sync["Form"].Focus()
|
||||
|
||||
# maybe this is not the best place to load and execute config file?
|
||||
# maybe community can help?
|
||||
if ($PARAM_CONFIG) {
|
||||
Invoke-WPFImpex -type "import" -Config $PARAM_CONFIG
|
||||
if ($PARAM_RUN) {
|
||||
while ($sync.ProcessRunning) {
|
||||
Start-Sleep -Seconds 5
|
||||
}
|
||||
Start-Sleep -Seconds 5
|
||||
|
||||
Write-Host "Applying tweaks..."
|
||||
Invoke-WPFtweaksbutton
|
||||
while ($sync.ProcessRunning) {
|
||||
Start-Sleep -Seconds 5
|
||||
}
|
||||
Start-Sleep -Seconds 5
|
||||
|
||||
Write-Host "Installing features..."
|
||||
Invoke-WPFFeatureInstall
|
||||
while ($sync.ProcessRunning) {
|
||||
Start-Sleep -Seconds 5
|
||||
}
|
||||
|
||||
Start-Sleep -Seconds 5
|
||||
Write-Host "Installing applications..."
|
||||
while ($sync.ProcessRunning) {
|
||||
Start-Sleep -Seconds 1
|
||||
}
|
||||
Invoke-WPFInstall
|
||||
Start-Sleep -Seconds 5
|
||||
|
||||
Write-Host "Done."
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
# Load Checkboxes and Labels outside of the Filter function only once on startup for performance reasons
|
||||
@ -528,5 +540,8 @@ $sync["SponsorMenuItem"].Add_Click({
|
||||
$Height = $sync.configs.themes.$ctttheme.CustomDialogHeight
|
||||
Show-CustomDialog -Message $authorInfo -Width $Width -Height $Height -FontSize $FontSize -HeaderFontSize $HeaderFontSize -IconSize $IconSize -EnableScroll $true
|
||||
})
|
||||
$sync["Form"].ShowDialog() | out-null
|
||||
Stop-Transcript
|
||||
|
||||
if (!$PARAM_RUN) {
|
||||
$sync["Form"].ShowDialog() | out-null
|
||||
Stop-Transcript
|
||||
}
|
||||
|
Reference in New Issue
Block a user