System.Windows.Messagebox 超时 Powershell

LCa*_*res 0 windows powershell timeout messagebox popup

我需要询问 [System.Windows.MessageBox] 的超时问题,代码如下:

\n\n

“logX”(如log1、log2或log3)是写入文件的函数,仅更改Log3。Log3 写入后执行“退出”(离开脚本)。我们不需要这个函数如何工作

\n\n
#Funcion para comprobar si existe el token o no.\nfunction Token{\n#comprobamos si existe el fichero\n$token = Test-Path $dir_token\nif($token -eq $True){\n    #Existe el fichero\n    $ftoken = 1\n}else{ \n    #No existe el fichero\n    $ftoken = 0\n}\nreturn $ftoken\n}\n\n#Asignamos direcci\xc3\xb3n de token\n$Global:dir_token = "D:\\Nuevacarpeta\\Nueva carpeta\\token.txt"\n#Ejecutamos la funcion de Token para saber si existe ahora mismo\n$ftoken = Token\n#Preparamos la ruta del log\n$log = "D:\\Nuevacarpeta\\log\\log.txt"\n\n#Creamos la variable Outlook transformandolo en un objeto (Commobject de Powershell)\n$Global:outlook = New-Object -comobject outlook.application\n$comprobaroutlook = Get-variable -name outlook\n$valueoutlook = $comprobaroutlook.Value\n\nif($valueoutlook.Equals("")){\n\n$msgBoxInput =  [System.Windows.MessageBox]::Show(\'Outlook no se puede tratar, SCRIPT FAIL, para Borrar token y continuar con la ejecuci\xc3\xb3n pulsa SI, para no borrar el token e ignorar este mensaje pulse NO\',\'ERROR CRITICO SCRIPT\',\'YesNo\',\'Error\')\nswitch  ($msgBoxInput) {\n  \'Yes\' {\n  ## Do something \n  Remove-Item -Path $dir_token\n  [System.Windows.MessageBox]::Show("BORRADO TOKEN")\n  Log3("Borrado token, proxima ejecuci\xc3\xb3n sera correcta")  \n  }\n  \'No\' {\n  ## Do something\n  [System.Windows.MessageBox]::Show("No hacemos nada, esperamos")\n  Log3("No tiene contenido la variable outlook")\n  }\n}\n}elseif($ftoken -eq 1){\n\n$msgBoxIn = [System.Windows.MessageBox]::Show(\'Outlook no se puede tratar, SCRIPT FAIL, para Borrar token y continuar con la ejecuci\xc3\xb3n pulsa SI, para no borrar el token e ignorar este mensaje pulse NO\',\'ERROR CRITICO SCRIPT\',\'YesNo\',\'Error\')     \nswitch  ($msgBoxIn) {\n  \'Yes\' {\n  ## Do something \n  Remove-Item -Path $dir_token\n  [System.Windows.MessageBox]::Show("BORRADO TOKEN")\n  Log3("Borrado token, proxima ejecuci\xc3\xb3n sera correcta") \n  }\n  \'No\' {\n  ## Do something\n  [System.Windows.MessageBox]::Show("No hacemos nada, esperamos")\n  Log3("Existe Token")\n  }\n}\n\n}else{\n\n  New-Item -Path $dir_token -ItemType File\n\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

我询问此通道中的超时:

\n\n

-[System.Windows.MessageBox]::Show("BORRADO TOKEN")\n-[System.Windows.MessageBox]::Show("No hacemos nada, esperamos")

\n\n

此消息仅提供信息,我想在屏幕中弹出后 5 分钟显示并关闭它

\n

小智 7

您可以使用Wscript.ShellCOM 对象。

$sh = New-Object -ComObject "Wscript.Shell"
$intButton = $sh.Popup("Testing",2,"Title",0+64)
Run Code Online (Sandbox Code Playgroud)

这里

句法

  intButton = objShell.Popup(strText,[nSecondsToWait],[strTitle],[nType]) 
Run Code Online (Sandbox Code Playgroud)

论据

objShell : 一个 WScript.Shell 对象

strText :包含要在弹出消息框中显示的文本的字符串值。

nSecondsToWait:显示弹出消息框的最大时间长度(以秒为单位,可选,默认=无限)

strTitle :标题文本字符串,可选。

nType :按钮和图标的类型(数字,可选)这些决定了消息框的使用方式。

IntButton :按钮的编号(整数值) 这是当用户确定消息框时返回的值。

的含义nType是通过组合下表中的值来确定的:

按钮类型

值 说明
0 确定按钮。
1 确定和取消按钮。
2 中止、重试和忽略按钮。
3 是、否和取消按钮。
4 是和否按钮。
5 重试和取消按钮。

图标类型
值 说明
16 “停止标记”图标。
32 “问号”图标。
48 “感叹号”图标。
64“信息标记”图标。

IntButton返回值的可能值:

值 说明
1 确定按钮
2 取消按钮
3
中止按钮 4 重试按钮
5 忽略按钮
6 是按钮
7 否按钮

如果用户在 nSecondsToWait 之前没有单击按钮,则 intButton 设置为 -1。