0

I need to ask about timeout with [System.Windows.MessageBox] the code is the next:

"logX" (like log1, log2 or log3) are function to write in a file, only change Log3. Log3 do "exit"(leave the Script) after write. We dont need the how work this function

#Funcion para comprobar si existe el token o no.
function Token{
#comprobamos si existe el fichero
$token = Test-Path $dir_token
if($token -eq $True){
    #Existe el fichero
    $ftoken = 1
}else{ 
    #No existe el fichero
    $ftoken = 0
}
return $ftoken
}

#Asignamos dirección de token
$Global:dir_token = "D:\Nuevacarpeta\Nueva carpeta\token.txt"
#Ejecutamos la funcion de Token para saber si existe ahora mismo
$ftoken = Token
#Preparamos la ruta del log
$log = "D:\Nuevacarpeta\log\log.txt"

#Creamos la variable Outlook transformandolo en un objeto (Commobject de Powershell)
$Global:outlook = New-Object -comobject outlook.application
$comprobaroutlook = Get-variable -name outlook
$valueoutlook = $comprobaroutlook.Value

if($valueoutlook.Equals("")){

$msgBoxInput =  [System.Windows.MessageBox]::Show('Outlook no se puede tratar, SCRIPT FAIL, para Borrar token y continuar con la ejecución pulsa SI, para no borrar el token e ignorar este mensaje pulse NO','ERROR CRITICO SCRIPT','YesNo','Error')
switch  ($msgBoxInput) {
  'Yes' {
  ## Do something 
  Remove-Item -Path $dir_token
  [System.Windows.MessageBox]::Show("BORRADO TOKEN")
  Log3("Borrado token, proxima ejecución sera correcta")  
  }
  'No' {
  ## Do something
  [System.Windows.MessageBox]::Show("No hacemos nada, esperamos")
  Log3("No tiene contenido la variable outlook")
  }
}
}elseif($ftoken -eq 1){

$msgBoxIn = [System.Windows.MessageBox]::Show('Outlook no se puede tratar, SCRIPT FAIL, para Borrar token y continuar con la ejecución pulsa SI, para no borrar el token e ignorar este mensaje pulse NO','ERROR CRITICO SCRIPT','YesNo','Error')     
switch  ($msgBoxIn) {
  'Yes' {
  ## Do something 
  Remove-Item -Path $dir_token
  [System.Windows.MessageBox]::Show("BORRADO TOKEN")
  Log3("Borrado token, proxima ejecución sera correcta") 
  }
  'No' {
  ## Do something
  [System.Windows.MessageBox]::Show("No hacemos nada, esperamos")
  Log3("Existe Token")
  }
}

}else{

  New-Item -Path $dir_token -ItemType File

}

I ask about timeout in this lanes:

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

This message its only informative and i wanna show and close it 5 min after popup in the screen

LCabaAres
  • 15
  • 1
  • 10

1 Answers1

5

You can use the Wscript.Shell COM object.

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

From here:

Syntax

  intButton = objShell.Popup(strText,[nSecondsToWait],[strTitle],[nType]) 

Arguments

objShell : A WScript.Shell object

strText : String value containing the text you want to appear in the pop-up message box.

nSecondsToWait : Maximum length of time to display the pop-up message box (in seconds, Optional, default=infinite)

strTitle : Title text string, Optional.

nType : Type of buttons and icons (Numeric, Optional) These determine how the message box is used.

IntButton : Number of the button (Integer value) This is the value returned when the user OK's the message box.

The meaning of nType is determined by combining values from the 2 tables below:

Button Types

Value Description
0 OK button.
1 OK and Cancel buttons.
2 Abort, Retry, and Ignore buttons.
3 Yes, No, and Cancel buttons.
4 Yes and No buttons.
5 Retry and Cancel buttons.

Icon Types
Value Description
16 "Stop Mark" icon.
32 "Question Mark" icon.
48 "Exclamation Mark" icon.
64 "Information Mark" icon.

Possible values for IntButton the return value:

Value Description
1 OK button
2 Cancel button
3 Abort button
4 Retry button
5 Ignore button
6 Yes button
7 No button

If the user does not click a button before nSecondsToWait intButton is set to -1.

langstrom
  • 1,652
  • 11
  • 14
  • Good, this can resolve the problem. I see I cant automat [System.Windows.MessageBox] dont work in Script with schedule task. Finally i need to do this command and remake the Script. Thanks, +1 – LCabaAres Feb 08 '19 at 07:38
  • If this solves your problem, can you mark it as Answered? – langstrom Feb 08 '19 at 14:55