diff --git a/playbook/shopfloor-setup/gea-shopfloor-cmm/09-Setup-CMM.ps1 b/playbook/shopfloor-setup/gea-shopfloor-cmm/09-Setup-CMM.ps1 index 74e26dc..f1a5953 100644 --- a/playbook/shopfloor-setup/gea-shopfloor-cmm/09-Setup-CMM.ps1 +++ b/playbook/shopfloor-setup/gea-shopfloor-cmm/09-Setup-CMM.ps1 @@ -314,6 +314,32 @@ if (Test-Path -LiteralPath $restoreScript) { Write-CMMLog "Restore-CMM.ps1 not found at $restoreScript - skipping settings restore" 'WARN' } +# ============================================================================ +# Step 2.5: drop Register-PCDMIS-COM.bat on the SupportUser desktop +# ============================================================================ +# PC-DMIS COM must be registered for goCMM to connect, but /regserver no-ops +# until PC-DMIS is licensed - which happens manually post-image (clmadmin.exe). +# So we cannot register at imaging time; instead leave a one-click helper the +# tech runs AFTER activating the license. SupportUser is a pre-existing profile +# (see 03-ShellDefaults), so its Desktop exists now. Public Desktop would get +# reorganized by 06-OrganizeDesktop's sweep, so target SupportUser directly; +# fall back to Public Desktop only if the SupportUser profile is absent. +$regBat = Join-Path $stagingRoot 'Register-PCDMIS-COM.bat' +if (Test-Path -LiteralPath $regBat) { + $deskTargets = @() + if (Test-Path 'C:\Users\SupportUser') { $deskTargets += 'C:\Users\SupportUser\Desktop' } + else { $deskTargets += 'C:\Users\Public\Desktop' } + foreach ($d in $deskTargets) { + try { + if (-not (Test-Path $d)) { New-Item -Path $d -ItemType Directory -Force | Out-Null } + Copy-Item -LiteralPath $regBat -Destination (Join-Path $d 'Register-PCDMIS-COM.bat') -Force + Write-CMMLog "Staged Register-PCDMIS-COM.bat -> $d" + } catch { Write-CMMLog "Failed to stage Register-PCDMIS-COM.bat to ${d}: $_" 'WARN' } + } +} else { + Write-CMMLog "Register-PCDMIS-COM.bat not in staging ($regBat) - desktop helper NOT placed" 'WARN' +} + # ============================================================================ # Step 3: Conditional cleanup of the bootstrap staging dir # ============================================================================ diff --git a/playbook/shopfloor-setup/gea-shopfloor-cmm/Register-PCDMIS-COM.bat b/playbook/shopfloor-setup/gea-shopfloor-cmm/Register-PCDMIS-COM.bat new file mode 100644 index 0000000..11b8180 --- /dev/null +++ b/playbook/shopfloor-setup/gea-shopfloor-cmm/Register-PCDMIS-COM.bat @@ -0,0 +1,57 @@ +@echo off +REM ============================================================================ +REM Register-PCDMIS-COM.bat - register the PC-DMIS COM / automation server. +REM +REM WHY: goCMM connects to PC-DMIS over COM. If the COM server is not +REM registered, goCMM throws "Object reference not set to an instance of an +REM object" at startup (it calls Type.GetTypeFromProgID on the PC-DMIS ProgID, +REM gets null, then Activator.CreateInstance(null) -> ArgumentNullException). +REM +REM IMPORTANT: PC-DMIS must be LICENSED FIRST. /regserver does NOT register the +REM COM server until a valid license is present. Activate the license with +REM clmadmin.exe, THEN run this. Safe to re-run any time goCMM stops connecting. +REM +REM Needs admin - this script self-elevates via UAC. +REM ============================================================================ + +REM --- self-elevate if not already running as admin --- +net session >nul 2>&1 +if %errorlevel% neq 0 ( + echo Requesting administrator rights... + powershell -NoProfile -Command "Start-Process -FilePath '%~f0' -Verb RunAs" + exit /b +) + +echo ================================================================ +echo Register PC-DMIS COM server (run AFTER licensing PC-DMIS) +echo ================================================================ +echo. + +setlocal enabledelayedexpansion +set "FOUND=" +for %%D in ( + "C:\Program Files\Hexagon" + "C:\Program Files (x86)\Hexagon" + "C:\Program Files\WAI" + "C:\Program Files (x86)\WAI" +) do ( + if exist %%~D ( + for /f "delims=" %%F in ('dir /b /s "%%~D\Pcdlrn.exe" 2^>nul') do ( + set "FOUND=1" + echo Registering: %%F + "%%F" /regserver + if !errorlevel! equ 0 (echo OK) else (echo regserver returned !errorlevel!) + ) + ) +) + +echo. +if not defined FOUND ( + echo ERROR: Pcdlrn.exe not found. Is PC-DMIS installed? +) else ( + echo Done. + echo If goCMM still errors, confirm PC-DMIS is LICENSED ^(clmadmin.exe^) and + echo that you ran this AFTER activating the license, then re-run. +) +echo. +pause