276 lines
10 KiB
PowerShell
276 lines
10 KiB
PowerShell
# Elevate privileges if needed
|
|
if (-not ([Security.Principal.WindowsPrincipal]::new([Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(
|
|
[Security.Principal.WindowsBuiltInRole]::Administrator))) {
|
|
Start-Process powershell -Verb runAs -ArgumentList $MyInvocation.MyCommand.Definition
|
|
exit
|
|
}
|
|
|
|
function Show-Banner {
|
|
Clear-Host
|
|
Write-Host @"
|
|
MAGICIS - SUPPORT A VETERAN
|
|
"@ -ForegroundColor Cyan
|
|
}
|
|
|
|
function Show-Menu {
|
|
Show-Banner
|
|
Write-Host "========== CONFIGURATION MENU ==========" -ForegroundColor Cyan
|
|
Write-Host "1. Enable High/Ultimate Performance Power Plan"
|
|
Write-Host "2. Rename PC using MAC Address"
|
|
Write-Host "3. Run both (1 and 2)"
|
|
Write-Host "4. Install Notepad++, .NET 8, VC++"
|
|
Write-Host "5. Disable UAC, Notifications and tweaks"
|
|
Write-Host "6. Run magicis-install.ps1"
|
|
Write-Host "7. Exit"
|
|
Write-Host "========================================`n"
|
|
}
|
|
|
|
function Set-HighPerformancePowerPlan {
|
|
Write-Output "`nActivating best available power plan (Ultimate -> High)..."
|
|
|
|
$guidUltimate = "{e9a42b02-d5df-448d-aa00-03f14749eb61}" # Ultimate Performance
|
|
$guidHigh = "{8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c}" # High Performance
|
|
$activated = $false
|
|
|
|
# Try Ultimate Performance first
|
|
try {
|
|
powercfg -setactive $guidUltimate 2>$null
|
|
if ($LASTEXITCODE -eq 0) {
|
|
Write-Output "Ultimate Performance plan activated."
|
|
$activated = $true
|
|
}
|
|
} catch {
|
|
# ignore, will fallback
|
|
}
|
|
|
|
# Fallback to High Performance
|
|
if (-not $activated) {
|
|
try {
|
|
powercfg -setactive $guidHigh 2>$null
|
|
if ($LASTEXITCODE -eq 0) {
|
|
Write-Output "High Performance plan activated (fallback)."
|
|
$activated = $true
|
|
} else {
|
|
Write-Output "Failed to activate High Performance plan (exit code $LASTEXITCODE)."
|
|
}
|
|
} catch {
|
|
Write-Output "Failed to activate High Performance plan: $_"
|
|
}
|
|
}
|
|
|
|
if ($activated) {
|
|
try {
|
|
powercfg -change -monitor-timeout-ac 0
|
|
powercfg -change -monitor-timeout-dc 0
|
|
powercfg -change -standby-timeout-ac 0
|
|
powercfg -change -standby-timeout-dc 0
|
|
Write-Output "Power settings applied successfully.`n"
|
|
} catch {
|
|
Write-Output "Plan activated, but failed to change some timeouts: $_"
|
|
}
|
|
} else {
|
|
Write-Output "No supported performance plan could be activated.`n"
|
|
}
|
|
}
|
|
|
|
function Rename-PCToMac() {
|
|
Write-Output "`nRenaming PC using MAC address..."
|
|
$mac = (Get-NetAdapter -InterfaceAlias "*Ethernet*" | Select-Object -First 1 -ExpandProperty MacAddress) -replace '-', ''
|
|
if ($mac) {
|
|
Rename-Computer -NewName "$mac" -Force
|
|
Write-Output "Computer renamed to: $mac"
|
|
Write-Output "Please restart the computer to apply the change.`n"
|
|
} else {
|
|
Write-Output "Could not retrieve MAC address.`n"
|
|
}
|
|
}
|
|
|
|
function Install-CommonTools() {
|
|
Write-Output "`nInstalling tools and dependencies via winget..."
|
|
try {
|
|
winget install -e --id Notepad++.Notepad++ --accept-source-agreements --accept-package-agreements
|
|
winget install -e --id Microsoft.DotNet.DesktopRuntime.8 --accept-source-agreements --accept-package-agreements
|
|
winget install -e --id Microsoft.VCRedist.2015+.x64 --accept-source-agreements --accept-package-agreements
|
|
Write-Output "Installation completed.`n"
|
|
} catch {
|
|
Write-Output "Installation error: $_"
|
|
}
|
|
}
|
|
|
|
# Log path
|
|
$Global:LogFile = "C:\temp\system_tweaks.log"
|
|
|
|
# Helper function to log messages to console and file
|
|
function Write-Log {
|
|
param(
|
|
[string]$Message,
|
|
[string]$Level = "INFO"
|
|
)
|
|
|
|
$timestamp = (Get-Date).ToString("yyyy-MM-dd HH:mm:ss")
|
|
$line = "[$timestamp] [$Level] $Message"
|
|
|
|
# Console
|
|
Write-Output $line
|
|
|
|
# File
|
|
try {
|
|
$dir = Split-Path $Global:LogFile -Parent
|
|
if (-not (Test-Path $dir)) {
|
|
New-Item -ItemType Directory -Path $dir -Force | Out-Null
|
|
}
|
|
Add-Content -Path $Global:LogFile -Value $line
|
|
} catch {
|
|
Write-Output "Error writing log to $Global:LogFile : $_"
|
|
}
|
|
}
|
|
|
|
function Disable-UACAndNotifications {
|
|
Write-Log "Disabling UAC and notifications..."
|
|
try {
|
|
Set-ItemProperty -Path REGISTRY::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System -Name EnableLUA -Value 0
|
|
Set-ItemProperty -Path REGISTRY::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System -Name ConsentPromptBehaviorAdmin -Value 0
|
|
New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows Defender Security Center\Notifications" -Force | Out-Null
|
|
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows Defender Security Center\Notifications" -Name "DisableEnhancedNotifications" -Type DWord -Value 1
|
|
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Search -Name SearchBoxTaskbarMode -Value 0 -Type DWord -Force
|
|
Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False
|
|
Write-Log "UAC and notifications disabled."
|
|
} catch {
|
|
Write-Log "Error configuring system: $_" "ERROR"
|
|
}
|
|
}
|
|
|
|
function Set-ActiveEthernetAsPrivate {
|
|
Write-Log "Setting active Ethernet connections to Private..."
|
|
try {
|
|
$ethUp = Get-NetAdapter -Physical |
|
|
Where-Object { $_.Status -eq 'Up' -and $_.Name -notmatch 'Wi-Fi|WLAN|Wireless|Bluetooth|Virtual' }
|
|
|
|
if (-not $ethUp) {
|
|
Write-Log "No active physical Ethernet interfaces found."
|
|
return
|
|
}
|
|
|
|
foreach ($adap in $ethUp) {
|
|
$profile = Get-NetConnectionProfile -InterfaceIndex $adap.InterfaceIndex -ErrorAction SilentlyContinue
|
|
if ($null -ne $profile) {
|
|
if ($profile.NetworkCategory -ne 'Private') {
|
|
Set-NetConnectionProfile -InterfaceIndex $adap.InterfaceIndex -NetworkCategory Private -ErrorAction Stop
|
|
Write-Log "Interface '$($adap.Name)' set to Private."
|
|
} else {
|
|
Write-Log "Interface '$($adap.Name)' is already Private."
|
|
}
|
|
}
|
|
}
|
|
} catch {
|
|
Write-Log "Error setting network to Private: $_" "ERROR"
|
|
}
|
|
}
|
|
|
|
function Enable-TaskbarAutoHide {
|
|
Write-Log "Enabling taskbar auto-hide..."
|
|
try {
|
|
New-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Force | Out-Null
|
|
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name "TaskbarAutoHide" -Type DWord -Value 1
|
|
|
|
Write-Log "Restarting Explorer..."
|
|
Stop-Process -Name explorer -ErrorAction SilentlyContinue
|
|
Start-Process explorer.exe
|
|
Write-Log "Auto-hide enabled."
|
|
} catch {
|
|
Write-Log "Error configuring taskbar auto-hide: $_" "ERROR"
|
|
}
|
|
}
|
|
|
|
function Disable-FirewallNotifications {
|
|
Write-Log "Disabling Firewall notifications..."
|
|
try {
|
|
Set-NetFirewallProfile -Profile Domain,Public,Private -NotifyOnListen False -ErrorAction SilentlyContinue
|
|
|
|
$fwBase = "HKLM:\SOFTWARE\Policies\Microsoft\WindowsFirewall"
|
|
$profiles = @("DomainProfile","PrivateProfile","PublicProfile","StandardProfile")
|
|
foreach ($p in $profiles) {
|
|
$key = Join-Path $fwBase $p
|
|
New-Item -Path $key -Force | Out-Null
|
|
New-ItemProperty -Path $key -Name "DisableNotifications" -PropertyType DWord -Value 1 -Force | Out-Null
|
|
}
|
|
|
|
New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows Defender Security Center\Notifications" -Force | Out-Null
|
|
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows Defender Security Center\Notifications" -Name "DisableEnhancedNotifications" -Type DWord -Value 1
|
|
|
|
Write-Log "Firewall notifications disabled."
|
|
} catch {
|
|
Write-Log "Error disabling Firewall notifications: $_" "ERROR"
|
|
}
|
|
}
|
|
|
|
function Disable-ExplorerSmartScreen {
|
|
Write-Log "Disabling Windows SmartScreen (Explorer)..."
|
|
try {
|
|
$pol = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\System"
|
|
New-Item -Path $pol -Force | Out-Null
|
|
New-ItemProperty -Path $pol -Name "EnableSmartScreen" -PropertyType DWord -Value 0 -Force | Out-Null
|
|
New-ItemProperty -Path $pol -Name "ShellSmartScreenLevel" -PropertyType String -Value "Off" -Force | Out-Null
|
|
|
|
$exp = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer"
|
|
New-Item -Path $exp -Force | Out-Null
|
|
New-ItemProperty -Path $exp -Name "SmartScreenEnabled" -PropertyType String -Value "Off" -Force | Out-Null
|
|
|
|
Write-Log "Explorer SmartScreen disabled."
|
|
} catch {
|
|
Write-Log "Error disabling SmartScreen: $_" "ERROR"
|
|
}
|
|
}
|
|
|
|
function Run-MagicisInstall {
|
|
Write-Log "Starting magicis-install.ps1..."
|
|
try {
|
|
$scriptPath = Join-Path -Path $PSScriptRoot -ChildPath "magicis-install.ps1"
|
|
if (-not (Test-Path $scriptPath)) {
|
|
Write-Log "magicis-install.ps1 not found at $scriptPath. Please place it in the same folder or update the path." "ERROR"
|
|
return
|
|
}
|
|
# Run with bypass to avoid policy issues; current session is already elevated
|
|
powershell -NoProfile -ExecutionPolicy Bypass -File $scriptPath
|
|
Write-Log "magicis-install.ps1 finished."
|
|
} catch {
|
|
Write-Log "Error running magicis-install.ps1: $_" "ERROR"
|
|
}
|
|
}
|
|
|
|
function Apply-SystemTweaks {
|
|
Write-Log "==== Starting to apply system settings ===="
|
|
Disable-UACAndNotifications
|
|
Set-ActiveEthernetAsPrivate
|
|
Enable-TaskbarAutoHide
|
|
Disable-FirewallNotifications
|
|
Disable-ExplorerSmartScreen
|
|
Write-Log "==== All settings applied successfully ===="
|
|
}
|
|
|
|
|
|
# Main loop
|
|
do {
|
|
Show-Menu
|
|
$choice = Read-Host "Select an option (1-7)"
|
|
|
|
switch ($choice) {
|
|
"1" { Set-HighPerformancePowerPlan }
|
|
"2" { Rename-PCToMac }
|
|
"3" {
|
|
Set-HighPerformancePowerPlan
|
|
Rename-PCToMac
|
|
}
|
|
"4" { Install-CommonTools }
|
|
"5" { Apply-SystemTweaks }
|
|
"6" { Run-MagicisInstall }
|
|
"7" { Write-Host "`nExiting..." -ForegroundColor Yellow }
|
|
default { Write-Host "`nInvalid option. Please try again." -ForegroundColor Red }
|
|
}
|
|
|
|
if ($choice -notin @("7")) {
|
|
Pause
|
|
}
|
|
|
|
} while ($choice -ne "7")
|