Replace em-dash characters with plain hyphens across the 5 shopfloor setup scripts (avoids cp1252 mojibake in .bat files and keeps the PowerShell sources consistent). Also adds [Parameter(Position=1)] to Write-PreInstallLog so the Level argument can be passed positionally. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
142 lines
4.9 KiB
PowerShell
142 lines
4.9 KiB
PowerShell
# Set-MachineNumber.ps1 - Update UDC + eDNC machine number on a Standard shopfloor PC
|
|
#
|
|
# Purpose:
|
|
# Both UDC and eDNC use the same per-machine identifier ("Workstation Number" /
|
|
# "Machine Number"). On Standard PCs imaged via PXE preinstall, both are installed
|
|
# with a placeholder. When the PC is brought to its physical machine and assigned
|
|
# a real number, this helper updates both apps in one step.
|
|
#
|
|
# Persistence locations updated:
|
|
# 1. UDC: C:\ProgramData\UDC\udc_settings.json (GeneralSettings.MachineNumber)
|
|
# 2. eDNC: HKLM:\SOFTWARE\WOW6432Node\GE Aircraft Engines\DNC\General\MachineNo
|
|
#
|
|
# After updating, kills any running UDC.exe and relaunches it with the new args
|
|
# so the in-memory state matches the persisted value.
|
|
#
|
|
# Run as SupportUser (admin). Requires write access to ProgramData and HKLM.
|
|
|
|
Add-Type -AssemblyName Microsoft.VisualBasic
|
|
Add-Type -AssemblyName System.Windows.Forms
|
|
|
|
$udcSettingsPath = "C:\ProgramData\UDC\udc_settings.json"
|
|
$udcExePath = "C:\Program Files\UDC\UDC.exe"
|
|
$ednRegPath = "HKLM:\SOFTWARE\WOW6432Node\GE Aircraft Engines\DNC\General"
|
|
$site = "West Jefferson"
|
|
|
|
# --- Read current values for display ---
|
|
$currentUdc = $null
|
|
$currentEdnc = $null
|
|
|
|
if (Test-Path $udcSettingsPath) {
|
|
try {
|
|
$json = Get-Content $udcSettingsPath -Raw | ConvertFrom-Json
|
|
$currentUdc = $json.GeneralSettings.MachineNumber
|
|
} catch {
|
|
$currentUdc = "(unreadable: $_)"
|
|
}
|
|
}
|
|
|
|
if (Test-Path $ednRegPath) {
|
|
try {
|
|
$currentEdnc = (Get-ItemProperty -Path $ednRegPath -Name MachineNo -ErrorAction Stop).MachineNo
|
|
} catch {
|
|
$currentEdnc = $null
|
|
}
|
|
}
|
|
|
|
# --- Show prompt with current state ---
|
|
$promptLines = @()
|
|
$promptLines += "Current UDC machine number: $(if ($currentUdc) { $currentUdc } else { '(not set)' })"
|
|
$promptLines += "Current eDNC machine number: $(if ($currentEdnc) { $currentEdnc } else { '(not set)' })"
|
|
$promptLines += ""
|
|
$promptLines += "Enter the new Machine Number for this PC:"
|
|
$prompt = $promptLines -join "`n"
|
|
|
|
$new = [Microsoft.VisualBasic.Interaction]::InputBox($prompt, "Set Machine Number", "")
|
|
|
|
if ([string]::IsNullOrWhiteSpace($new)) {
|
|
Write-Host "Cancelled."
|
|
exit 0
|
|
}
|
|
|
|
$new = $new.Trim()
|
|
|
|
# --- Validate: digits only (loosen if you need alphanumerics) ---
|
|
if ($new -notmatch '^\d+$') {
|
|
[System.Windows.Forms.MessageBox]::Show(
|
|
"Machine number must be digits only.`n`nYou entered: '$new'",
|
|
"Invalid Machine Number",
|
|
[System.Windows.Forms.MessageBoxButtons]::OK,
|
|
[System.Windows.Forms.MessageBoxIcon]::Error
|
|
) | Out-Null
|
|
exit 1
|
|
}
|
|
|
|
$results = @()
|
|
|
|
# --- 1. Stop UDC.exe before editing its JSON (avoid stale shutdown write) ---
|
|
$udcProcs = Get-Process UDC -ErrorAction SilentlyContinue
|
|
if ($udcProcs) {
|
|
Write-Host "Stopping UDC.exe ($($udcProcs.Count) instance(s))..."
|
|
$udcProcs | ForEach-Object {
|
|
try {
|
|
$_.Kill()
|
|
$_.WaitForExit(5000) | Out-Null
|
|
} catch {
|
|
Write-Warning "Failed to stop UDC.exe (PID $($_.Id)): $_"
|
|
}
|
|
}
|
|
Start-Sleep -Seconds 1
|
|
}
|
|
|
|
# --- 2. Update UDC settings JSON ---
|
|
if (Test-Path $udcSettingsPath) {
|
|
try {
|
|
$json = Get-Content $udcSettingsPath -Raw | ConvertFrom-Json
|
|
$json.GeneralSettings.MachineNumber = $new
|
|
$json | ConvertTo-Json -Depth 99 | Set-Content -Path $udcSettingsPath -Encoding UTF8
|
|
Write-Host "UDC: $currentUdc -> $new"
|
|
$results += "UDC updated to $new"
|
|
} catch {
|
|
Write-Warning "Failed to update UDC settings: $_"
|
|
$results += "UDC FAILED: $_"
|
|
}
|
|
} else {
|
|
Write-Warning "UDC settings file not found at $udcSettingsPath. Run UDC.exe at least once to initialize."
|
|
$results += "UDC: settings file missing (run UDC.exe once first)"
|
|
}
|
|
|
|
# --- 3. Update eDNC MachineNo registry value ---
|
|
if (Test-Path $ednRegPath) {
|
|
try {
|
|
Set-ItemProperty -Path $ednRegPath -Name MachineNo -Value $new -Type String -Force
|
|
Write-Host "eDNC: $currentEdnc -> $new"
|
|
$results += "eDNC updated to $new"
|
|
} catch {
|
|
Write-Warning "Failed to update eDNC MachineNo: $_"
|
|
$results += "eDNC FAILED: $_"
|
|
}
|
|
} else {
|
|
Write-Warning "eDNC registry key not found at $ednRegPath. Is eDNC installed?"
|
|
$results += "eDNC: registry key missing (eDNC not installed?)"
|
|
}
|
|
|
|
# --- 4. Relaunch UDC.exe with new args (if installed) ---
|
|
if (Test-Path $udcExePath) {
|
|
try {
|
|
Start-Process -FilePath $udcExePath -ArgumentList @("-site", "`"$site`"", "-machine", $new)
|
|
Write-Host "UDC.exe relaunched."
|
|
} catch {
|
|
Write-Warning "Failed to relaunch UDC.exe: $_"
|
|
}
|
|
}
|
|
|
|
# --- 5. Show summary ---
|
|
$summary = ($results -join "`n") + "`n`nTo apply eDNC changes, restart any running DncMain.exe."
|
|
[System.Windows.Forms.MessageBox]::Show(
|
|
$summary,
|
|
"Set Machine Number - Done",
|
|
[System.Windows.Forms.MessageBoxButtons]::OK,
|
|
[System.Windows.Forms.MessageBoxIcon]::Information
|
|
) | Out-Null
|