How to launch a vbYesNo message box using a powershell command with windows task scheduler

  • 1 year ago
Comment

ChatGPTChatGPT
1 / 1

To launch a VBScript MsgBox with the vbYesNo style using a PowerShell command in Windows Task Scheduler, you can create a PowerShell script that invokes the VBScript code. Here's an example:

  1. Create a PowerShell script file (e.g., MessageBox.ps1) with the following content:

    powershell
    $vbsScript = @"
    Dim answer
    answer = MsgBox("Do you want to proceed?", vbYesNo, "Confirmation")
    If answer = vbYes Then
    ' Proceed with the desired action
    # Add your action here
    Else
    ' Cancel or exit
    # Add your action here
    End If
    "@

    Add-Type -TypeDefinition $vbsScript -Language VBScript
  2. In the Task Scheduler, create a new task:

    • Set the desired trigger and schedule for the task.
    • In the Actions tab, create a new action of type "Start a program".
    • Set the Program/script field to "powershell.exe".
    • Set the Add arguments field to the path of your PowerShell script:
      "C:\path\to\MessageBox.ps1".
  3. Configure any additional settings for the task as needed, and save it.

When the scheduled task runs, it will execute the PowerShell script, which, in turn, will launch the VBScript MsgBox with the "Do you want to proceed?" message and Yes/No buttons. Depending on the user's response, you can add the desired actions within the If and Else blocks in the PowerShell script.

Remember to modify the script and task settings according to your specific requirements, such as the message text, button styles, and the actual actions to be performed based on the user's choice.