运行脚本返回的控制台输出和标准输出都自带换行符\r\n

BUG反馈 · 21 次浏览
爻乂一 创建于 3天2小时前

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)

爻乂一 最后更新于 2026/10/1

回复内容
CL 2天9小时前
#1

原始输出什么就返回什么的

回复主贴