First commit
This commit is contained in:
275
01-ENABLE-1.ps1
Normal file
275
01-ENABLE-1.ps1
Normal file
@@ -0,0 +1,275 @@
|
||||
# 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")
|
||||
108
01-ENABLE.ps1
Normal file
108
01-ENABLE.ps1
Normal file
@@ -0,0 +1,108 @@
|
||||
# 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. Rename PC using MAC Address AND RESTART"
|
||||
Write-Host "2. Run magicis-install.ps1"
|
||||
Write-Host "3. Exit"
|
||||
Write-Host "========================================`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 "Restarting Computer to apply settings in 10 seconds"
|
||||
Start-Sleep -Seconds 10
|
||||
Restart-Computer -Force
|
||||
} else {
|
||||
Write-Output "Could not retrieve MAC address.`n"
|
||||
}
|
||||
}
|
||||
|
||||
# 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 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"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# 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")
|
||||
BIN
Agent-1.0.129.zip
Normal file
BIN
Agent-1.0.129.zip
Normal file
Binary file not shown.
6
config.json
Normal file
6
config.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"installationType" : "POS",
|
||||
"agentVersion" : "1.0.0",
|
||||
"posVersion" : null,
|
||||
"gameTerminalVersion" : null
|
||||
}
|
||||
307
magicis-install.ps1
Normal file
307
magicis-install.ps1
Normal file
@@ -0,0 +1,307 @@
|
||||
# MAGICIS INSTALL - Terminal Type Selector
|
||||
# Runs C:\magicis\agent.bat, adjusts C:\magicis\config.json, then enables kiosk mode and restarts.
|
||||
# Kiosk mode: AutoAdminLogon (user=magicis / pass=magicis123) + Shell = c:\magicis\agent\agent.exe
|
||||
# With resilient logging (C:\magicis\install.log -> C:\ProgramData\magicis\install.log -> %TEMP%\magicis_install.log)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
# ---- Elevation check ----
|
||||
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(
|
||||
[Security.Principal.WindowsBuiltInRole] "Administrator")) {
|
||||
$self = if ($PSCommandPath) { $PSCommandPath } else { $MyInvocation.MyCommand.Path }
|
||||
Start-Process -FilePath "powershell.exe" -Verb RunAs -ArgumentList $self
|
||||
exit
|
||||
}
|
||||
|
||||
# ---- Paths/Constants ----
|
||||
$ConfigDir = 'C:\magicis'
|
||||
$ConfigPath = Join-Path $ConfigDir 'config.json'
|
||||
$AgentBat = Join-Path $ConfigDir 'agent.bat'
|
||||
$ShellPath = 'c:\magicis\agent\agent.exe'
|
||||
$KioskUser = 'magicis'
|
||||
$KioskPass = '124578Magicis'
|
||||
|
||||
# ---- Logging (resilient) ----
|
||||
$Global:LogPath = $null
|
||||
function Initialize-Log {
|
||||
$candidates = @(
|
||||
'C:\magicis\install.log',
|
||||
'C:\ProgramData\magicis\install.log',
|
||||
(Join-Path $env:TEMP 'magicis_install.log')
|
||||
)
|
||||
foreach ($p in $candidates) {
|
||||
try {
|
||||
$dir = Split-Path $p -Parent
|
||||
if (-not (Test-Path $dir)) {
|
||||
New-Item -ItemType Directory -Path $dir -Force | Out-Null
|
||||
}
|
||||
"----- LOG START $(Get-Date -Format s) -----" | Out-File -FilePath $p -Encoding UTF8 -Append
|
||||
$Global:LogPath = $p
|
||||
break
|
||||
} catch { }
|
||||
}
|
||||
}
|
||||
function Write-Log([string]$Message) {
|
||||
try {
|
||||
if (-not $Global:LogPath) { Initialize-Log }
|
||||
$line = "[{0}] {1}" -f (Get-Date -Format "yyyy-MM-dd HH:mm:ss"), $Message
|
||||
if ($Global:LogPath) { Add-Content -Path $Global:LogPath -Value $line -Encoding UTF8 }
|
||||
} catch { }
|
||||
}
|
||||
Initialize-Log
|
||||
Write-Log "Script started."
|
||||
|
||||
# ---- Helpers ----
|
||||
function Get-ConfigObject {
|
||||
try {
|
||||
$raw = Get-Content -Path $ConfigPath -Raw -ErrorAction Stop
|
||||
Write-Log "Read config.json ($($raw.Length) chars)."
|
||||
return ($raw | ConvertFrom-Json -ErrorAction Stop)
|
||||
}
|
||||
catch {
|
||||
Write-Log "ERROR reading/parsing config.json: $($_.Exception.Message)"
|
||||
Write-Host "Failed to read or parse $ConfigPath." -ForegroundColor Red
|
||||
return $null
|
||||
}
|
||||
}
|
||||
function Save-ConfigObject($obj) {
|
||||
try {
|
||||
$json = $obj | ConvertTo-Json -Depth 5
|
||||
$json | Set-Content -Path $ConfigPath -Encoding UTF8 -Force
|
||||
Write-Log "config.json saved successfully."
|
||||
}
|
||||
catch {
|
||||
Write-Log "ERROR saving config.json: $($_.Exception.Message)"
|
||||
Write-Host "Failed to save ${ConfigPath}: $($_.Exception.Message)" -ForegroundColor Red
|
||||
}
|
||||
}
|
||||
function Set-InstallationType($typeString) {
|
||||
if (-not (Test-Path -Path $ConfigPath)) {
|
||||
Write-Log "config.json not found. installationType not changed."
|
||||
Write-Host "Config not found at $ConfigPath. Nothing changed." -ForegroundColor Yellow
|
||||
return
|
||||
}
|
||||
$cfg = Get-ConfigObject
|
||||
if ($null -eq $cfg) { return }
|
||||
$prev = $cfg.installationType
|
||||
$cfg.installationType = $typeString
|
||||
Save-ConfigObject -obj $cfg
|
||||
Write-Log "installationType changed: '$prev' -> '$typeString'."
|
||||
Write-Host "installationType: '$prev' -> '$typeString' ($ConfigPath)" -ForegroundColor Green
|
||||
}
|
||||
function Run-Agent {
|
||||
if (-not (Test-Path -Path $ConfigDir)) {
|
||||
Write-Log "Directory $ConfigDir not found."
|
||||
Write-Host "Directory $ConfigDir was not found." -ForegroundColor Yellow
|
||||
return $false
|
||||
}
|
||||
if (-not (Test-Path -Path $AgentBat)) {
|
||||
Write-Log "agent.bat not found at $AgentBat."
|
||||
Write-Host "agent.bat not found at $AgentBat" -ForegroundColor Red
|
||||
return $false
|
||||
}
|
||||
try {
|
||||
Start-Process -FilePath "cmd.exe" -ArgumentList "/c","agent.bat" -WorkingDirectory $ConfigDir -WindowStyle Hidden | Out-Null
|
||||
Write-Log "agent.bat started."
|
||||
Write-Host "agent.bat started..." -ForegroundColor Cyan
|
||||
return $true
|
||||
}
|
||||
catch {
|
||||
Write-Log "ERROR starting agent.bat: $($_.Exception.Message)"
|
||||
Write-Host "Failed to start agent.bat: $($_.Exception.Message)" -ForegroundColor Red
|
||||
return $false
|
||||
}
|
||||
}
|
||||
function Stop-InteractiveProcesses {
|
||||
Write-Log "Stopping processes: java/javaw/godot..."
|
||||
$names = @('java','javaw','godot')
|
||||
foreach ($n in $names) {
|
||||
try { Stop-Process -Name $n -Force -ErrorAction SilentlyContinue } catch {}
|
||||
}
|
||||
try {
|
||||
$procs = Get-CimInstance Win32_Process -ErrorAction SilentlyContinue | Where-Object {
|
||||
$_.Name -match '(?i)java|godot' -or $_.Description -match '(?i)OpenJDK Platform Binary|Godot'
|
||||
}
|
||||
foreach ($p in $procs) {
|
||||
try { Stop-Process -Id $p.ProcessId -Force -ErrorAction SilentlyContinue } catch {}
|
||||
}
|
||||
} catch {}
|
||||
Write-Log "Process stop routine completed."
|
||||
Write-Host "Requested processes terminated (java/javaw/Godot if running)." -ForegroundColor DarkCyan
|
||||
}
|
||||
function Wait-ForConfig([int]$TimeoutSec = 30) {
|
||||
Write-Log "Waiting for config.json (timeout ${TimeoutSec}s)..."
|
||||
$elapsed = 0
|
||||
while ($elapsed -lt $TimeoutSec) {
|
||||
if (Test-Path -Path $ConfigPath) {
|
||||
Write-Log "config.json detected after ${elapsed}s."
|
||||
return $true
|
||||
}
|
||||
Start-Sleep -Seconds 1
|
||||
$elapsed++
|
||||
}
|
||||
Write-Log "config.json NOT detected within timeout."
|
||||
return $false
|
||||
}
|
||||
|
||||
# ---- Kiosk Mode ----
|
||||
function Ensure-LocalAdminUser([string]$User, [string]$Pass) {
|
||||
try {
|
||||
$secure = ConvertTo-SecureString $Pass -AsPlainText -Force
|
||||
$existing = Get-LocalUser -Name $User -ErrorAction SilentlyContinue
|
||||
if ($null -eq $existing) {
|
||||
New-LocalUser -Name $User -Password $secure -PasswordNeverExpires -AccountNeverExpires -FullName $User -Description "Kiosk AutoLogon user" | Out-Null
|
||||
Write-Log "Created local user '$User'."
|
||||
} else {
|
||||
if ($existing.Enabled -eq $false) { Enable-LocalUser -Name $User }
|
||||
$existing | Set-LocalUser -Password $secure
|
||||
Set-LocalUser -Name $User -PasswordNeverExpires $true
|
||||
Write-Log "Updated local user '$User' (enabled & password set)."
|
||||
}
|
||||
$admins = Get-LocalGroupMember -Group 'Administrators' -ErrorAction SilentlyContinue
|
||||
$inGroup = $admins | Where-Object { $_.Name -match ("(?i)\\$User$") }
|
||||
if (-not $inGroup) {
|
||||
Add-LocalGroupMember -Group 'Administrators' -Member $User -ErrorAction Stop
|
||||
Write-Log "Added '$User' to Administrators."
|
||||
} else {
|
||||
Write-Log "User '$User' already in Administrators."
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Log "ERROR ensuring local user '$User': $($_.Exception.Message)"
|
||||
Write-Host "Failed to ensure local user '$User': $($_.Exception.Message)" -ForegroundColor Red
|
||||
throw
|
||||
}
|
||||
}
|
||||
function Enable-AutoAdminLogon([string]$User, [string]$Pass) {
|
||||
$key = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon'
|
||||
try {
|
||||
#New-Item -Path $key -Force | Out-Null
|
||||
Set-ItemProperty -Path $key -Name 'AutoAdminLogon' -Value '1' -Type String
|
||||
Set-ItemProperty -Path $key -Name 'ForceAutoLogon' -Value '1' -Type String
|
||||
Set-ItemProperty -Path $key -Name 'DefaultUserName' -Value $User -Type String
|
||||
Set-ItemProperty -Path $key -Name 'DefaultDomainName' -Value '.' -Type String
|
||||
Set-ItemProperty -Path $key -Name 'DefaultPassword' -Value $Pass -Type String
|
||||
Set-ItemProperty -Path $key -Name 'DisableCAD' -Value 1 -Type DWord
|
||||
Write-Log "AutoAdminLogon configured for user '$User'."
|
||||
}
|
||||
catch {
|
||||
Write-Log "ERROR setting AutoAdminLogon: $($_.Exception.Message)"
|
||||
Write-Host "Failed to set AutoAdminLogon registry: $($_.Exception.Message)" -ForegroundColor Red
|
||||
throw
|
||||
}
|
||||
}
|
||||
function Set-KioskShell([string]$ShellExe) {
|
||||
$key = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon'
|
||||
try {
|
||||
Set-ItemProperty -Path $key -Name 'Shell' -Value $ShellExe -Type String
|
||||
Write-Log "Kiosk shell set to '$ShellExe'."
|
||||
}
|
||||
catch {
|
||||
Write-Log "ERROR setting kiosk shell: $($_.Exception.Message)"
|
||||
Write-Host "Failed to set kiosk shell: $($_.Exception.Message)" -ForegroundColor Red
|
||||
throw
|
||||
}
|
||||
}
|
||||
function Enable-KioskMode([string]$SelectedType) {
|
||||
Write-Host "Enabling kiosk mode and restarting $SelectedType..." -ForegroundColor Cyan
|
||||
Write-Log "Enabling kiosk mode for '$SelectedType'..."
|
||||
Ensure-LocalAdminUser -User $KioskUser -Pass $KioskPass
|
||||
Enable-AutoAdminLogon -User $KioskUser -Pass $KioskPass
|
||||
Set-KioskShell -ShellExe $ShellPath
|
||||
Write-Log "Kiosk mode configured. Rebooting in 5 seconds."
|
||||
Write-Host "Kiosk mode configured: AutoAdminLogon=user '$KioskUser', Shell='$ShellPath'." -ForegroundColor Green
|
||||
Write-Host "Rebooting in 5 seconds..." -ForegroundColor Yellow
|
||||
Start-Sleep -Seconds 5
|
||||
Restart-Computer -Force
|
||||
}
|
||||
|
||||
# ---- Proper Exit (closes window) ----
|
||||
function Exit-Script {
|
||||
Write-Log "Exit chosen by user. Terminating host..."
|
||||
try {
|
||||
if ($Host.Name -match 'ConsoleHost|Windows PowerShell ISE Host') {
|
||||
Stop-Process -Id $PID -Force
|
||||
} else {
|
||||
exit 0
|
||||
}
|
||||
} catch {
|
||||
exit 0
|
||||
}
|
||||
}
|
||||
|
||||
function Show-Menu {
|
||||
Clear-Host
|
||||
Write-Host "==============================" -ForegroundColor Cyan
|
||||
Write-Host " MAGICIS INSTALL (choose terminal type) " -ForegroundColor Cyan
|
||||
Write-Host "==============================" -ForegroundColor Cyan
|
||||
Write-Host "1 - GAME TERMINAL"
|
||||
Write-Host "2 - POS"
|
||||
Write-Host "3 - LOADER"
|
||||
Write-Host "4 - Exit"
|
||||
Write-Host ""
|
||||
}
|
||||
|
||||
# ---- Main loop ----
|
||||
while ($true) {
|
||||
Show-Menu
|
||||
$choice = Read-Host "Enter an option (1-4)"
|
||||
Write-Log "Menu choice: $choice"
|
||||
|
||||
switch ($choice) {
|
||||
'1' {
|
||||
if (Run-Agent) {
|
||||
Start-Sleep -Seconds 10
|
||||
Write-Log "Option 1: waited 10s, stopping processes..."
|
||||
Stop-InteractiveProcesses
|
||||
if (Wait-ForConfig -TimeoutSec 30) {
|
||||
Set-InstallationType -typeString 'GAME_TERMINAL'
|
||||
} else {
|
||||
Write-Host "config.json did not appear within 30s." -ForegroundColor Yellow
|
||||
Write-Log "config.json not found within 30s (option 1)."
|
||||
}
|
||||
}
|
||||
Write-Host "Enabling kiosk mode and restarting GAME TERMINAL..." -ForegroundColor Cyan
|
||||
Enable-KioskMode -SelectedType 'GAME TERMINAL'
|
||||
}
|
||||
'2' {
|
||||
if (Run-Agent) {
|
||||
Start-Sleep -Seconds 10
|
||||
Write-Log "Option 2: waited 10s, stopping processes..."
|
||||
Stop-InteractiveProcesses
|
||||
if (Wait-ForConfig -TimeoutSec 30) {
|
||||
Set-InstallationType -typeString 'POS'
|
||||
} else {
|
||||
Write-Host "config.json did not appear within 30s." -ForegroundColor Yellow
|
||||
Write-Log "config.json not found within 30s (option 2)."
|
||||
}
|
||||
}
|
||||
Write-Host "Enabling kiosk mode and restarting POS..." -ForegroundColor Cyan
|
||||
Enable-KioskMode -SelectedType 'POS'
|
||||
}
|
||||
'3' {
|
||||
if (Run-Agent) {
|
||||
Start-Sleep -Seconds 10
|
||||
Write-Log "Option 3: waited 10s, stopping processes..."
|
||||
Stop-InteractiveProcesses
|
||||
if (Wait-ForConfig -TimeoutSec 30) {
|
||||
Set-InstallationType -typeString 'LOADER'
|
||||
} else {
|
||||
Write-Host "config.json did not appear within 30s." -ForegroundColor Yellow
|
||||
Write-Log "config.json not found within 30s (option 3)."
|
||||
}
|
||||
}
|
||||
Write-Host "Enabling kiosk mode and restarting LOADER..." -ForegroundColor Cyan
|
||||
Enable-KioskMode -SelectedType 'LOADER'
|
||||
}
|
||||
'4' {
|
||||
Write-Host "Exiting..." -ForegroundColor Cyan
|
||||
Exit-Script
|
||||
}
|
||||
default {
|
||||
Write-Log "Invalid choice: $choice"
|
||||
Write-Host "Invalid option. Please choose 1, 2, 3, or 4." -ForegroundColor Yellow
|
||||
Start-Sleep -Milliseconds 900
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user