首页 > 解决方案 > Powershell Wscript.Shell 弹出窗口超时不超时

问题描述

我正在使用$wshell.Popup($time, $time, 'Warning', 48 + 4096)一个超时的弹出窗口。当我编写超时时间为 5 的代码时,一切都运行良好,但是当我投入生产时,它以较长的超时时间工作失败。所以我写了下面的代码来说明奇怪的行为。超过 19 秒的值在我的计算机上不起作用。有没有人遇到同样的问题?如何解决这个问题?

(我有 PSVersion:5.1.18362.1171 & VBScript.5.8.16384)

$time = 1
$increment = 1
$Exclamation = 48
$ShowOnTop = 4096
$wshell = New-Object -ComObject Wscript.Shell
while($true){
    $start = get-date
    $null = $wshell.Popup($time, $time, 'Warning', $Exclamation + $ShowOnTop)
    $delta = (get-date) - $start
    write-host "pop up $time took $($delta.TotalSeconds)" -ForegroundColor Green
    $time += $increment
}

输出:

pop up 1 took 1.1034666
pop up 2 took 2.1012811
pop up 3 took 3.1027432
pop up 4 took 4.1011674
pop up 5 took 8.8805263
pop up 6 took 6.1285214
pop up 7 took 13.8968735
pop up 8 took 8.1029593
pop up 9 took 11.9174401
pop up 10 took 19.0161058
pop up 11 took 19.0150746
pop up 12 took 19.0156603
pop up 13 took 19.0159296
pop up 14 took 19.030777
pop up 15 took 19.0175581
pop up 16 took 19.0388007
pop up 17 took 19.0392871
pop up 18 took 19.043456
pop up 19 did not end after 270 seconds...

作为隔离问题的测试,我创建了这个 vbs 文件。30秒后成功超时:

CreateObject("WScript.Shell").Popup "Hello!", 30, "Title", 4144

标签: vbapowershell

解决方案


推荐阅读