Files
winutil/scripts/start.ps1
T

64 lines
1.5 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
2024-01-12 00:34:41 -06:00
if (!(Test-Path -Path $ENV:TEMP)) {
New-Item -ItemType Directory -Force -Path $ENV:TEMP
}
+3
2023-03-07 12:28:00 -08:00
Start-Transcript $ENV:TEMP\Winutil.log -Append
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 = @{}
$sync.ProcessRunning = $false
2023-07-13 15:46:00 -05:00
+12
2023-11-28 16:11:11 -06:00
$currentPid = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$principal = new-object System.Security.Principal.WindowsPrincipal($currentPid)
$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator
2023-07-13 15:46:00 -05:00
2024-01-15 11:32:19 -06:00
+12
2023-11-28 16:11:11 -06:00
if ($principal.IsInRole($adminRole))
{
$Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Admin)"
clear-host
2023-07-13 15:46:00 -05:00
}
+12
2023-11-28 16:11:11 -06:00
else
{
$newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell";
$newProcess.Arguments = $myInvocation.MyCommand.Definition;
$newProcess.Verb = "runas";
[System.Diagnostics.Process]::Start($newProcess);
break
}