From 227cb21c2446bca12986253b2e888abcd1cd3dd7 Mon Sep 17 00:00:00 2001 From: ChrisTitusTech Date: Fri, 28 Jun 2024 22:16:05 +0000 Subject: [PATCH] Compile Winutil --- winutil.ps1 | 497 ++++++++++++++++++++++++++-------------------------- 1 file changed, 249 insertions(+), 248 deletions(-) diff --git a/winutil.ps1 b/winutil.ps1 index fa4943cb..701373b9 100644 --- a/winutil.ps1 +++ b/winutil.ps1 @@ -62,52 +62,52 @@ If (([Security.Principal.WindowsIdentity]::GetCurrent()).Owner.Value -ne "S-1-5- # Set PowerShell window title $Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Admin)" clear-host -function ConvertTo-Icon { +function ConvertTo-Icon { <# - + .DESCRIPTION This function will convert PNG to ICO file .EXAMPLE ConvertTo-Icon -bitmapPath "$env:TEMP\cttlogo.png" -iconPath $iconPath #> - param( [Parameter(Mandatory=$true)] - $bitmapPath, + param( [Parameter(Mandatory=$true)] + $bitmapPath, $iconPath = "$env:temp\newicon.ico" - ) - - Add-Type -AssemblyName System.Drawing - - if (Test-Path $bitmapPath) { - $b = [System.Drawing.Bitmap]::FromFile($bitmapPath) - $icon = [System.Drawing.Icon]::FromHandle($b.GetHicon()) - $file = New-Object System.IO.FileStream($iconPath, 'OpenOrCreate') - $icon.Save($file) - $file.Close() - $icon.Dispose() - #explorer "/SELECT,$iconpath" - } - else { Write-Warning "$BitmapPath does not exist" } + ) + + Add-Type -AssemblyName System.Drawing + + if (Test-Path $bitmapPath) { + $b = [System.Drawing.Bitmap]::FromFile($bitmapPath) + $icon = [System.Drawing.Icon]::FromHandle($b.GetHicon()) + $file = New-Object System.IO.FileStream($iconPath, 'OpenOrCreate') + $icon.Save($file) + $file.Close() + $icon.Dispose() + #explorer "/SELECT,$iconpath" + } + else { Write-Warning "$BitmapPath does not exist" } } function Copy-Files { <# - + .DESCRIPTION This function will make all modifications to the registry .EXAMPLE Set-WinUtilRegistry -Name "PublishUserActivities" -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\System" -Type "DWord" -Value "0" - - #> + + #> param ( - [string] $Path, - [string] $Destination, - [switch] $Recurse = $false, + [string] $Path, + [string] $Destination, + [switch] $Recurse = $false, [switch] $Force = $false ) - try { + try { $files = Get-ChildItem -Path $path -Recurse:$recurse Write-Host "Copy $($files.Count)(s) from $path to $destination" @@ -126,9 +126,9 @@ function Copy-Files { else { Write-Debug "Copy from $($file.FullName) to $($destination+$restpath)" - Copy-Item $file.FullName ($destination+$restpath) -ErrorAction SilentlyContinue -Force:$force + Copy-Item $file.FullName ($destination+$restpath) -ErrorAction SilentlyContinue -Force:$force Set-ItemProperty -Path ($destination+$restpath) -Name IsReadOnly -Value $false - } + } } Write-Progress -Activity "Copy Windows files" -Status "Ready" -Completed } @@ -140,17 +140,17 @@ function Copy-Files { function Get-LocalizedYesNo { <# .SYNOPSIS - This function runs choice.exe and captures its output to extract yes no in a localized Windows - + This function runs choice.exe and captures its output to extract yes no in a localized Windows + .DESCRIPTION The function retrieves the output of the command 'cmd /c "choice nul"' and converts the default output for Yes and No in the localized format, such as "Yes=, No=". - + .EXAMPLE $yesNoArray = Get-LocalizedYesNo Write-Host "Yes=$($yesNoArray[0]), No=$($yesNoArray[1])" #> - + # Run choice and capture its options as output # The output shows the options for Yes and No as "[Y,N]?" in the (partitially) localized format. # eg. English: [Y,N]? @@ -160,7 +160,7 @@ function Get-LocalizedYesNo { # Spanish: [S,N]? # Italian: [S,N]? # Russian: [Y,N]? - + $line = cmd /c "choice nul" $charactersArray = @() $regexPattern = '([a-zA-Z])' @@ -169,17 +169,18 @@ function Get-LocalizedYesNo { Write-Debug "According to takeown.exe local Yes is $charactersArray[0]" # Return the array of characters return $charactersArray + } -function Get-Oscdimg { +function Get-Oscdimg { <# - + .DESCRIPTION This function will download oscdimg file from github Release folders and put it into env:temp folder .EXAMPLE Get-Oscdimg #> - param( [Parameter(Mandatory=$true)] + param( [Parameter(Mandatory=$true)] [string]$oscdimgPath ) $oscdimgPath = "$env:TEMP\oscdimg.exe" @@ -196,7 +197,7 @@ function Get-Oscdimg { } else { Write-Host "Hashes do not match. File may be corrupted or tampered with." } -} +} function Get-TabXaml { <# .SYNOPSIS @@ -212,8 +213,8 @@ function Get-TabXaml { .EXAMPLE Get-TabXaml "applications" 3 #> - - + + param( [Parameter(Mandatory=$true)] $tabname, $columncount = 0 @@ -279,7 +280,7 @@ function Get-TabXaml { # Dot-source the Get-WPFObjectName function . .\functions\private\Get-WPFObjectName - + $categorycontent = $($category -replace '^.__', '') $categoryname = Get-WPFObjectName -type "Label" -name $categorycontent $blockXml += "