mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-01-15 17:30:37 -06:00
106 lines
4.1 KiB
PowerShell
106 lines
4.1 KiB
PowerShell
function Invoke-WinUtilTweaks {
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
Invokes the function associated with each provided checkbox
|
|
|
|
.PARAMETER CheckBox
|
|
The checkbox to invoke
|
|
|
|
.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,
|
|
$KeepServiceStartup = $true
|
|
)
|
|
|
|
Write-Debug "Tweaks: $($CheckBox)"
|
|
if($undo) {
|
|
$Values = @{
|
|
Registry = "OriginalValue"
|
|
ScheduledTask = "OriginalState"
|
|
Service = "OriginalType"
|
|
ScriptType = "UndoScript"
|
|
}
|
|
|
|
} else {
|
|
$Values = @{
|
|
Registry = "Value"
|
|
ScheduledTask = "State"
|
|
Service = "StartupType"
|
|
OriginalService = "OriginalType"
|
|
ScriptType = "InvokeScript"
|
|
}
|
|
}
|
|
if($sync.configs.tweaks.$CheckBox.ScheduledTask) {
|
|
$sync.configs.tweaks.$CheckBox.ScheduledTask | ForEach-Object {
|
|
Write-Debug "$($psitem.Name) and state is $($psitem.$($values.ScheduledTask))"
|
|
Set-WinUtilScheduledTask -Name $psitem.Name -State $psitem.$($values.ScheduledTask)
|
|
}
|
|
}
|
|
if($sync.configs.tweaks.$CheckBox.service) {
|
|
Write-Debug "KeepServiceStartup is $KeepServiceStartup"
|
|
$sync.configs.tweaks.$CheckBox.service | ForEach-Object {
|
|
# Reset variable on each iteraction
|
|
$canchangeservice = $false
|
|
$service = $null
|
|
|
|
$servicename = $psitem.Name
|
|
try {
|
|
$service = Get-Service -Name "$servicename" -ErrorAction Stop
|
|
} catch [Microsoft.PowerShell.Commands.ServiceCommandException] {
|
|
Write-Debug "[Invoke-WinUtilTweaks] Service $servicename was not found"
|
|
} catch {
|
|
Write-Debug "[Invoke-WinUtilTweaks] Unable to validate $servicename due to unhandled exception"
|
|
Write-Debug "$($psitem.Exception.Message)"
|
|
}
|
|
|
|
# Note:
|
|
# The check for !($undo) is required, without it the script will throw an error for accessing unavailable memeber,
|
|
# which's the 'OriginalService' Property
|
|
if($service -AND $KeepServiceStartup -AND !$undo) {
|
|
if($service.StartType.ToString() -ne $psitem.$($values.OriginalService)) {
|
|
Write-Debug "Service $servicename 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))"
|
|
} else {
|
|
$canchangeservice = $true
|
|
}
|
|
}
|
|
|
|
if($service -AND ($canchangeservice -OR $undo)) {
|
|
Write-Host "Setting Service $servicename to $($psitem.$($values.Service))"
|
|
Set-Service -InputObject $service -StartupType $psitem.$($values.Service)
|
|
}
|
|
}
|
|
}
|
|
if($sync.configs.tweaks.$CheckBox.registry) {
|
|
$sync.configs.tweaks.$CheckBox.registry | ForEach-Object {
|
|
Write-Debug "$($psitem.Name) and state is $($psitem.$($values.registry))"
|
|
Set-WinUtilRegistry -Name $psitem.Name -Path $psitem.Path -Type $psitem.Type -Value $psitem.$($values.registry)
|
|
}
|
|
}
|
|
if($sync.configs.tweaks.$CheckBox.$($values.ScriptType)) {
|
|
$sync.configs.tweaks.$CheckBox.$($values.ScriptType) | ForEach-Object {
|
|
Write-Debug "$($psitem) and state is $($psitem.$($values.ScriptType))"
|
|
$Scriptblock = [scriptblock]::Create($psitem)
|
|
Invoke-WinUtilScript -ScriptBlock $scriptblock -Name $CheckBox
|
|
}
|
|
}
|
|
|
|
if(!$undo) {
|
|
if($sync.configs.tweaks.$CheckBox.appx) {
|
|
$sync.configs.tweaks.$CheckBox.appx | ForEach-Object {
|
|
Write-Debug "UNDO $($psitem.Name)"
|
|
Remove-WinUtilAPPX -Name $psitem
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|