
Set-ExecutionPolicy Bypass -Scope Process -Force
# 读取参数:第 1 个参数为等待毫秒数,默认 1000
$waitMs = 1000
if ($args.Count -ge 1) {
$parsed = 0
if ([int]::TryParse($args[0], [ref]$parsed)) {
$waitMs = $parsed
}
}
$progId = (Get-ItemProperty "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\https\UserChoice").ProgId
$command = (Get-ItemProperty "Registry::HKEY_CLASSES_ROOT\$progId\shell\open\command").'(default)'
# 提取可执行文件完整路径
if ($command -match '^"([^"]+)"') {
$exePath = $matches[1]
} elseif ($command -match '^(\S+\.exe)') {
$exePath = $matches[1]
} else {
[Console]::Write("unknown")
exit
}
# 获取进程名(不带 .exe)
$procName = [System.IO.Path]::GetFileNameWithoutExtension($exePath)
# 检查进程是否在运行
$running = Get-Process -Name $procName -ErrorAction SilentlyContinue
if (-not $running) {
Start-Process -FilePath $exePath
Start-Sleep -Milliseconds $waitMs
}
# 输出进程名,不带换行
[Console]::Write($procName)