mirror of
https://github.com/ChrisTitusTech/winutil
synced 2026-04-05 22:28:31 +00:00
* cleaned up typo, fixes, grammatical and other related fixes (#2) * typo in Lightshot app name * remove trailing comma in applications.json * consistent capitalization of Windows, WinGet - only user-facing text - includes update to devdocs-generator.ps1, so docs for tweaks modifying registry will have `Windows settings` rather than `windows settings` * various fixes for typos, style, punctuation and capitalization * capitalize 'AM' * Update README.md change formatting for GitHub UI interaction form code format (` `) to bold md Co-authored-by: Jay <65828559+Jay-o-Way@users.noreply.github.com> * typos and wording in docs --------- Co-authored-by: Jay <65828559+Jay-o-Way@users.noreply.github.com>
105 lines
4.2 KiB
PowerShell
105 lines
4.2 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 {
|
|
$changeservice = $true
|
|
|
|
# The check for !($undo) is required, without it the script will throw an error for accessing unavailable member, 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) {
|
|
$sync.configs.tweaks.$CheckBox.registry | ForEach-Object {
|
|
Write-Debug "$($psitem.Name) and state is $($psitem.$($values.registry))"
|
|
if (($psitem.Path -imatch "hku") -and !(Get-PSDrive -Name HKU -ErrorAction SilentlyContinue)) {
|
|
$null = (New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS)
|
|
if (Get-PSDrive -Name HKU -ErrorAction SilentlyContinue) {
|
|
Write-Debug "HKU drive created successfully."
|
|
} else {
|
|
Write-Debug "Failed to create HKU drive."
|
|
}
|
|
}
|
|
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
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|