# 1. 替换为你的网络CMD脚本URL $scriptUrl = "https://of.dianying360.cc/Ohook_Activation_AIO.cmd" # 2. 创建临时CMD文件(自动生成唯一路径,避免冲突) $tempCmdPath = [System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), "temp_exec.cmd") try { Write-Host "1. 正在获取网络脚本: $scriptUrl" -ForegroundColor Cyan # 网络请求(带超时,避免无限等待) $response = Invoke-WebRequest -Uri $scriptUrl -UseBasicParsing -TimeoutSec 20 -ErrorAction Stop # 检查内容是否为空 if (-not $response.Content) { throw "网络返回内容为空,URL可能无效" } Write-Host "2. 以GBK编码写入临时文件: $tempCmdPath" -ForegroundColor Cyan # 3. 关键:以GBK编码写入临时文件(确保cmd.exe能正确读取中文) $gbkEncoding = [System.Text.Encoding]::GetEncoding("GBK") [System.IO.File]::WriteAllBytes($tempCmdPath, $response.Content) Write-Host "`n3. 开始执行临时CMD脚本(窗口会停留)...`n" -ForegroundColor Yellow # 4. 执行临时文件(用 /k 保持cmd窗口,方便查看结果;执行后不删除临时文件,便于排查) cmd.exe /k "chcp 936 > nul && `"$tempCmdPath`" && pause" } catch { Write-Host "`n执行失败!原因:" -ForegroundColor Red Write-Host $_.Exception.Message -ForegroundColor Red if ($_.Exception.Response) { Write-Host "HTTP状态码:$($_.Exception.Response.StatusCode.Value__)" -ForegroundColor Red } Write-Host "`n按任意键退出..." -ForegroundColor Gray pause } finally { # 可选:执行完成后删除临时文件(若需保留排查,可注释这行) # if (Test-Path $tempCmdPath) { Remove-Item $tempCmdPath -Force } }