← Files thinkcellARCHIVED FILE
scripts/launch-thinkcell.ps1
2.92 KB · Nov 30, 2026 · 15:10 UTC
$ErrorActionPreference = 'Stop'
# Resolve the thinkcell add-in ProgID to its registered COM server.
# Check HKCU first
$registrations = @(
@{ ProgIdRoot = 'HKCU:\Software\Classes'; ClsidRoot = 'HKCU:\Software\Classes\CLSID' },
@{ ProgIdRoot = 'HKCU:\Software\Classes\Wow6432Node'; ClsidRoot = 'HKCU:\Software\Classes\Wow6432Node\CLSID' },
@{ ProgIdRoot = 'HKLM:\Software\Classes'; ClsidRoot = 'HKLM:\Software\Classes\CLSID' },
@{ ProgIdRoot = 'HKLM:\Software\Classes\Wow6432Node'; ClsidRoot = 'HKLM:\Software\Classes\Wow6432Node\CLSID' }
)
$serverPath = $null
$foundRegistration = $false
$foundDll = $false
foreach ($registration in $registrations) {
$progIdClsidKey = Join-Path (Join-Path $registration.ProgIdRoot 'thinkcell.addin') 'CLSID'
if (-not (Test-Path -LiteralPath $progIdClsidKey)) { continue }
$foundRegistration = $true
try {
# The default value at ...\thinkcell.addin\CLSID is the CLSID string.
$clsid = [string](Get-Item -LiteralPath $progIdClsidKey).GetValue('')
if ([string]::IsNullOrWhiteSpace($clsid)) { continue }
$clsid = $clsid.Trim().Trim('{', '}')
if ($clsid -notmatch '^[0-9A-Fa-f]{8}(-[0-9A-Fa-f]{4}){3}-[0-9A-Fa-f]{12}$') { continue }
$clsid = '{' + $clsid + '}'
$inprocKey = Join-Path (Join-Path (Join-Path $registration.ClsidRoot $clsid) 'InprocServer32') ''
if (-not (Test-Path -LiteralPath $inprocKey)) { continue }
$dllPath = [string](Get-Item -LiteralPath $inprocKey).GetValue('')
if ([string]::IsNullOrWhiteSpace($dllPath)) { continue }
$dllPath = [Environment]::ExpandEnvironmentVariables($dllPath.Trim().Trim('"'))
$dllPath = $dllPath -replace ',\s*\d+\s*$', ''
if (-not (Test-Path -LiteralPath $dllPath -PathType Leaf)) { continue }
$foundDll = $true
$installDirectory = Split-Path -Parent $dllPath
if ([string]::IsNullOrWhiteSpace($installDirectory)) { continue }
# Architecture-specific DLLs live below the directory containing tcmcp.exe.
if ((Split-Path -Leaf $installDirectory) -in @('x64', 'arm64')) {
$installDirectory = Split-Path -Parent $installDirectory
}
$candidate = Join-Path $installDirectory 'tcmcp.exe'
if (Test-Path -LiteralPath $candidate -PathType Leaf) {
$serverPath = (Resolve-Path -LiteralPath $candidate).Path
break
}
} catch {
# Ignore incomplete registry entries and continue to the next view.
}
}
if (-not $serverPath) {
$reason = if ($foundDll) { 'mcp_executable_missing' } elseif ($foundRegistration) { 'installation_incomplete' } else { 'thinkcell_not_found' }
# Keep MCP available so the host can discover and display installation help.
& (Join-Path $PSScriptRoot 'installation-help.ps1') -Reason $reason
exit $LASTEXITCODE
}
# Invoke directly so MCP input, output, and error streams remain attached.
& $serverPath
exit $LASTEXITCODE
SHA-256: 6d78b368e82ac2bdfe01cc1c9dae125b49ae104622fd7996d0c0057f15e46627