param( [Parameter(Mandatory=$true)] [string]$Path ) try { # 1. 路径预处理 # 展开环境变量 (虽然 .reg 路径通常是固定的,但支持一下没坏处) $ResolvedPath = $ExecutionContext.InvokeCommand.ExpandString($Path) # 2. 处理相对路径 # 如果路径是相对的 (./assets/...), 转换为绝对路径 if (-not (Test-Path $ResolvedPath) -and (Test-Path "$PWD\$ResolvedPath")) { $ResolvedPath = Join-Path $PWD $ResolvedPath } # 3. 检查文件是否存在 if (-not (Test-Path $ResolvedPath)) { Write-Warning "`n[RegImport] [Skip] Cannot find: $ResolvedPath" return } Write-Host "`n[RegImport] Importing: $(Split-Path $ResolvedPath -Leaf)" -ForegroundColor Gray # 4. 调用 reg.exe 导入 # 使用 Start-Process 以获取退出代码 $proc = Start-Process -FilePath "reg.exe" -ArgumentList "import", "`"$ResolvedPath`"" -Wait -PassThru -NoNewWindow if ($proc.ExitCode -eq 0) { Write-Host "`n[RegImport] Successfully imported." -ForegroundColor Green } else { Write-Error "`n[RegImport] Failed to import: $($proc.ExitCode)" } } catch { Write-Error "`n[RegImport] Failed to start process: $_" }