Files
winutil/scripts/start.ps1
T

91 lines
2.8 KiB
PowerShell
Raw Normal View History

+3
2023-03-07 12:28:00 -08:00
<#
.NOTES
Author : Chris Titus @christitustech
Runspace Author: @DeveloperDurp
GitHub : https://github.com/ChrisTitusTech
Version : #{replaceme}
#>
2024-01-15 11:32:19 -06:00
param (
[switch]$Debug,
[string]$Config,
[switch]$Run
)
# Set DebugPreference based on the -Debug switch
if ($Debug) {
$DebugPreference = "Continue"
}
if ($Config) {
$PARAM_CONFIG = $Config
}
$PARAM_RUN = $false
# Handle the -Run switch
if ($Run) {
Write-Host "Running config file tasks..."
$PARAM_RUN = $true
}
+3
2023-03-07 12:28:00 -08:00
2023-10-19 17:12:55 -05:00
# Load DLLs
+12
2023-11-28 16:11:11 -06:00
Add-Type -AssemblyName PresentationFramework
+3
2023-03-07 12:28:00 -08:00
Add-Type -AssemblyName System.Windows.Forms
2023-10-19 17:12:55 -05:00
# Variable to sync between runspaces
+3
2023-03-07 12:28:00 -08:00
$sync = [Hashtable]::Synchronized(@{})
$sync.PSScriptRoot = $PSScriptRoot
$sync.version = "#{replaceme}"
$sync.configs = @{}
2025-03-01 20:50:12 +01:00
$sync.Buttons = [System.Collections.Generic.List[PSObject]]::new()
+3
2023-03-07 12:28:00 -08:00
$sync.ProcessRunning = $false
2025-03-01 20:50:12 +01:00
$sync.selectedApps = [System.Collections.Generic.List[string]]::new()
$sync.ShowOnlySeleced = $false
$sync.currentTab = "Install"
$sync.ShowOnlySelected = $false
$sync.selectedAppsStackPanel
$sync.selectedAppsPopup
2023-07-13 15:46:00 -05:00
2024-08-28 18:52:53 +02:00
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Output "Winutil needs to be run as Administrator. Attempting to relaunch."
$argList = @()
$PSBoundParameters.GetEnumerator() | ForEach-Object {
$argList += if ($_.Value -is [switch] -and $_.Value) {
"-$($_.Key)"
2025-03-05 19:15:13 +01:00
} elseif ($_.Value -is [array]) {
"-$($_.Key) $($_.Value -join ',')"
} elseif ($_.Value) {
2025-03-05 19:15:13 +01:00
"-$($_.Key) '$($_.Value)'"
}
}
2025-03-05 19:15:13 +01:00
$script = if ($PSCommandPath) {
"& { & `'$($PSCommandPath)`' $($argList -join ' ') }"
} else {
2025-03-05 19:15:13 +01:00
"&([ScriptBlock]::Create((irm https://github.com/ChrisTitusTech/winutil/releases/latest/download/winutil.ps1))) $($argList -join ' ')"
}
2024-08-28 18:52:53 +02:00
2025-03-05 19:15:13 +01:00
$powershellCmd = if (Get-Command pwsh -ErrorAction SilentlyContinue) { "pwsh" } else { "powershell" }
$processCmd = if (Get-Command wt.exe -ErrorAction SilentlyContinue) { "wt.exe" } else { "$powershellCmd" }
2024-08-28 18:52:53 +02:00
2025-03-05 19:15:13 +01:00
if ($processCmd -eq "wt.exe") {
Start-Process $processCmd -ArgumentList "$powershellCmd -ExecutionPolicy Bypass -NoProfile -Command `"$script`"" -Verb RunAs
} else {
Start-Process $processCmd -ArgumentList "-ExecutionPolicy Bypass -NoProfile -Command `"$script`"" -Verb RunAs
}
2024-08-28 18:52:53 +02:00
+12
2023-11-28 16:11:11 -06:00
break
+26
2024-06-04 20:27:27 -07:00
}
$dateTime = Get-Date -Format "yyyy-MM-dd_HH-mm-ss"
$logdir = "$env:localappdata\winutil\logs"
[System.IO.Directory]::CreateDirectory("$logdir") | Out-Null
Start-Transcript -Path "$logdir\winutil_$dateTime.log" -Append -NoClobber | Out-Null
+26
2024-06-04 20:27:27 -07:00
# Set PowerShell window title
$Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Admin)"
clear-host