gpt4 book ai didi

Powershell - 提示用户然后在 xx 秒后过期提示

转载 作者:行者123 更新时间:2023-12-04 11:23:50 25 4
gpt4 key购买 nike

我正在尝试显示用户操作提示,如果没有采取任何操作,提示关闭并继续运行脚本。这是我的命令提示符对话框配置

$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes",""
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No",""
$cancel = New-Object System.Management.Automation.Host.ChoiceDescription "&Cancel",""
$choices = [System.Management.Automation.Host.ChoiceDescription[]]($yes,$no,$cancel)
$caption = "Caption message here"
$dialogmessage = ("Do you want to do something?:`n")

$timer = #set some value
#While the value is grater than zero keep the prompt open

while($timer -gt 0)
{
$result = $Host.UI.PromptForChoice($caption,$dialogmessage,$choices,0)

if($result -eq 0){Write-Host "Yes was selected"}

if($result -eq 1){Write-Host "No was selected"}

if($result -eq 2){Write-Host "Canceled by user.";exit}
}

我已经在互联网上上下看了看,我已经看到这是在 C# 中实现的,但对于我的生活,我无法确定 powershell 的最佳方法。我将不胜感激任何帮助。

谢谢

编辑:谢谢诺亚,这是更新的代码,它也更紧凑了!

        $prompt = new-object -comobject wscript.shell 
$answer = $prompt.popup("Do you want to do something?`n",5,"title",3)
if($answer -eq 6) {Write-Host "Yes was selected"}
if($answer -eq 7) {Write-Host "No was selected"}
if($answer -eq -1) {Write-Host "Timed out"}
if($answer -eq 2) {Write-Host "Canceled by user."}

最佳答案

给你...从我的一个旧脚本中挖出这个

#Value  Description   
#0 Show OK button.
#1 Show OK and Cancel buttons.
#2 Show Abort, Retry, and Ignore buttons.
#3 Show Yes, No, and Cancel buttons.
#4 Show Yes and No buttons.
#5 Show Retry and Cancel buttons.
#http://msdn.microsoft.com/en-us/library/x83z1d9f(v=vs.84).aspx

$a = new-object -comobject wscript.shell
$intAnswer = $a.popup("Question?",2,"Title",4) #first number is timeout, second is display.

#7 = no , 6 = yes, -1 = timeout

关于Powershell - 提示用户然后在 xx 秒后过期提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25729304/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com