# 09-Setup-WaxAndTrace.ps1 - Wax and Trace pc-type setup (Mitutoyo FormTracePak v6.213) # # Imaging-time install. Installs prereqs from manifest, then runs the # Mitutoyo FormTracePak v6.213 vendor installer from a mounted ISO. The # VB6 Setup.exe wrapper checks GetDriveType() == DRIVE_CDROM; Mount-DiskImage # satisfies that (a real CD drive isn't required). Per-asset calibration ISO # applies last. # # Layout at C:\WaxTrace-Install\ (xcopied by startnet.cmd): # waxtrace-manifest.json # 09-Setup-WaxAndTrace.ps1 (this file) # prereqs\vcredist_x86.exe (VC++ 2008 x86) # prereqs\vcredist_x64.exe (VC++ 2008 x64) # prereqs\vc_redist.x86.exe (VC++ 2017 x86) # prereqs\vc_redist.x64.exe (VC++ 2017 x64) # prereqs\HASPUserSetup.exe (Sentinel Runtime / HASP dongle driver) # formtracepak\FORMTRACEPAK-V6.213.iso (vendor installer ISO, ~2 GB) # calibrations\CAL-_serial-_probe-.iso (per-machine) # # Per-machine calibration is applied separately (mount cal ISO + run its # Setup.exe), keyed by C:\Enrollment\machine-number.txt. # # Legacy captured/ replay path (V6.0 zip + reg) retired 2026-05-21. The # captured-binary/ payload is still in the repo as a fallback - if the # v6.213 vendor install fails on a bay, fall back to the captured path # manually. See git history for the prior shape. # # Log: C:\Logs\WaxTrace\09-Setup-WaxAndTrace.log # C:\Logs\WaxTrace\install.log (written by Install-FromManifest) $ErrorActionPreference = 'Continue' # Mirror the CMM pattern (09-Setup-CMM.ps1): the script itself lives in the # shopfloor-setup tree (xcopied during WinPE), but the bulky bootstrap bundle # (prereqs + captured master + cal ISOs) lives at C:\WaxTrace-Install\, put # there by startnet.cmd from Y:\installers-post\waxtrace\ at imaging time. $stagingRoot = 'C:\WaxTrace-Install' $manifestPath = Join-Path $stagingRoot 'waxtrace-manifest.json' $libSource = Join-Path $PSScriptRoot '..\common\lib\Install-FromManifest.ps1' $logDir = 'C:\Logs\WaxTrace' $installLog = Join-Path $logDir 'install.log' $transcriptLog = Join-Path $logDir '09-Setup-WaxAndTrace.log' if (-not (Test-Path $logDir)) { New-Item -Path $logDir -ItemType Directory -Force | Out-Null } try { Start-Transcript -Path $transcriptLog -Append -Force | Out-Null } catch {} function Write-WTLog { param([string]$Message, [string]$Level = 'INFO') $stamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" Write-Host "[$stamp] [$Level] $Message" } Write-WTLog "================================================================" Write-WTLog "=== WaxTrace Setup (imaging-time) session start (PID $PID) ===" Write-WTLog "Running as: $([System.Security.Principal.WindowsIdentity]::GetCurrent().Name)" Write-WTLog "Script root: $PSScriptRoot" Write-WTLog "================================================================" # Status push - best-effort. $pxeStatusLib = Join-Path $PSScriptRoot '..\Shopfloor\lib\Send-PxeStatus.ps1' if (Test-Path $pxeStatusLib) { try { . $pxeStatusLib; Send-PxeStatus -Stage '09-Setup-WaxAndTrace: starting' -StageIndex 3 -StageTotal 8 } catch { } } foreach ($file in @('pc-type.txt','machine-number.txt')) { $path = "C:\Enrollment\$file" if (Test-Path -LiteralPath $path) { $content = (Get-Content -LiteralPath $path -First 1 -ErrorAction SilentlyContinue).Trim() Write-WTLog " $file = $content" } else { Write-WTLog " $file = (not present)" } } # ============================================================================ # Step 1: Prereqs via manifest (VC++ 2008 + 2017, HASP/Sentinel) # ============================================================================ if (-not (Test-Path $manifestPath)) { Write-WTLog "waxtrace-manifest.json not found at $manifestPath" 'ERROR' } elseif (-not (Test-Path $libSource)) { Write-WTLog "Install-FromManifest.ps1 not found at $libSource" 'ERROR' } else { Write-WTLog "Running Install-FromManifest (InstallerRoot=$PSScriptRoot)" & $libSource -ManifestPath $manifestPath -InstallerRoot $stagingRoot -LogFile $installLog $rc = $LASTEXITCODE Write-WTLog "Install-FromManifest returned $rc" } # ============================================================================ # Step 2: FormTracePak v6.213 vendor install (Mount-DiskImage + Setup.exe) # ============================================================================ # Detection: skip if Formtracepak already present (re-run safe). $ftpakExe = 'C:\Program Files (x86)\MitutoyoApp\Formtracepak\Formtracepak.exe' if (Test-Path -LiteralPath $ftpakExe) { Write-WTLog "Formtracepak.exe already present - skipping vendor install" } else { $ftpakIso = Join-Path $stagingRoot 'formtracepak\FORMTRACEPAK-V6.213.iso' if (-not (Test-Path -LiteralPath $ftpakIso)) { Write-WTLog "FormTracePak ISO not found at $ftpakIso" 'ERROR' } else { Write-WTLog "Mounting FormTracePak ISO: $ftpakIso" try { $img = Mount-DiskImage -ImagePath $ftpakIso -PassThru -ErrorAction Stop Start-Sleep -Seconds 8 $vol = Get-DiskImage -ImagePath $ftpakIso | Get-Volume $ftpakDrive = $vol.DriveLetter if (-not $ftpakDrive) { Write-WTLog " Mount succeeded but no drive letter assigned" 'ERROR' } else { Write-WTLog " mounted at ${ftpakDrive}: (volume label=$($vol.FileSystemLabel))" $setupExe = "${ftpakDrive}:\Setup.exe" if (-not [System.IO.File]::Exists($setupExe)) { Write-WTLog " Setup.exe not found at $setupExe" 'ERROR' } else { Write-WTLog " running $setupExe (VB6 wrapper - requires DRIVE_CDROM)" # Setup.exe is the VB6 wrapper. /silent + /qn flags often # ignored - the wrapper drives appSetup.exe + msiexec from # its own UI. If the wrapper insists on interactive, a tech # at the bay clicks through. Acceptable today; quieter # path is a future improvement (drive msiexec direct on # the wrapper's bundled MSIs). try { $p = Start-Process -FilePath $setupExe ` -WorkingDirectory "${ftpakDrive}:\" ` -ArgumentList '/silent' ` -Wait -PassThru Write-WTLog " Setup.exe exit $($p.ExitCode)" } catch { Write-WTLog " Setup.exe failed: $_" 'ERROR' } } } Dismount-DiskImage -ImagePath $ftpakIso -ErrorAction SilentlyContinue | Out-Null Write-WTLog " FormTracePak ISO dismounted" } catch { Write-WTLog " Mount-DiskImage failed: $_" 'ERROR' } } } # ============================================================================ # Step 3: Per-machine calibration ISO (mount + apply via cal Setup.exe) # ============================================================================ # Cal ISOs are keyed by asset_tag. Read machine-number.txt to pick the right # ISO. Each cal ISO is ~1.7MB and contains a tiny Mitutoyo wrapper Setup.exe # plus data/*.txt compensation tables for the bay's specific probe + serial. $mnPath = 'C:\Enrollment\machine-number.txt' $asset = $null if (Test-Path -LiteralPath $mnPath) { $asset = (Get-Content -LiteralPath $mnPath -First 1 -ErrorAction SilentlyContinue).Trim() } if (-not $asset) { Write-WTLog "machine-number.txt missing or empty - skipping calibration apply" 'WARN' } else { $calDir = Join-Path $stagingRoot 'calibrations' $candidate = Get-ChildItem $calDir -Filter "CAL-${asset}_*.iso" -ErrorAction SilentlyContinue | Select-Object -First 1 if (-not $candidate) { Write-WTLog "No cal ISO matched CAL-${asset}_*.iso in $calDir - skipping" 'WARN' } else { Write-WTLog "Mounting cal ISO: $($candidate.FullName)" try { $img = Mount-DiskImage -ImagePath $candidate.FullName -PassThru -ErrorAction Stop Start-Sleep -Seconds 2 $calDrive = ($img | Get-Volume).DriveLetter Write-WTLog " mounted at ${calDrive}:" $calSetup = "${calDrive}:\Setup.exe" if (Test-Path -LiteralPath $calSetup) { Write-WTLog " running cal Setup.exe (may prompt - VB6 wrapper, same vintage as main installer)" # Cal ISO Setup.exe is tiny (135KB) - if it prompts, user has to click through. # Acceptable today; future: dark-deploy the data/*.txt files directly into # the FormTracePak data dir + skip Setup.exe. $p = Start-Process -FilePath $calSetup -WorkingDirectory "${calDrive}:\" -Wait -PassThru Write-WTLog " cal Setup.exe exit $($p.ExitCode)" } else { Write-WTLog " cal Setup.exe not found on ISO at $calSetup" 'WARN' } Dismount-DiskImage -ImagePath $candidate.FullName -ErrorAction SilentlyContinue | Out-Null Write-WTLog " cal ISO dismounted" } catch { Write-WTLog " Mount-DiskImage failed: $_" 'ERROR' } } } # ============================================================================ # Step 4: OpenText auto-start at login (HostExplorer "WJ Shopfloor" session) # ============================================================================ $autoStartLib = Join-Path $PSScriptRoot '..\Shopfloor\lib\Set-OpenTextAutoStart.ps1' if (Test-Path -LiteralPath $autoStartLib) { Write-WTLog "Calling $autoStartLib" & $autoStartLib } else { Write-WTLog "Set-OpenTextAutoStart.ps1 not found at $autoStartLib - OpenText auto-start NOT configured" 'WARN' } if (Get-Command Send-PxeStatus -ErrorAction SilentlyContinue) { $finalStatus = if ($rc -eq 0) { 'in_progress' } else { 'failed' } $finalErr = if ($rc -ne 0) { "Install-FromManifest exit $rc" } else { '' } Send-PxeStatus -Stage '09-Setup-WaxAndTrace: complete' -StageIndex 4 -StageTotal 8 -Status $finalStatus -Error_ $finalErr } Write-WTLog "================================================================" Write-WTLog "=== WaxTrace Setup session end ===" Write-WTLog "================================================================" try { Stop-Transcript | Out-Null } catch {}