Ronen
Ronen

Reputation: 71

Task Scheduled Powershell script do not show message box

I have a Powershell script which scheduled to run overnight on several hosts. It executed by CMD script (wrapper) that set in the Task Scheduler.

In some cases I need to display a message to the user which will arrive in the morning and let him decide whether to continue the execution of the script or to abort it.

I'm using system.windows.froms.MessageBox::Show("My Message","status","4") in order to display the message.

It works perfectly when I executing the CMD script from windows PowerShell ISE console, however if I executed it from the task scheduler it skips the popup message.

Is there any solution for that issue?

Upvotes: 4

Views: 3954

Answers (1)

Frode F.
Frode F.

Reputation: 54881

The scheduled task has to be set to "Run only when user is logged on" for it to be able to interact with the desktop (eg display dialogs).

So if the main script has to run in the background (even when no user is logged in), you should split your program logic in 2 scripts run from 2 scheduled tasks:

  • One scheduled task running the background script with "run whether user is logged on or not"
  • A separate scheduled task running a script that checks whether the background task is still running, presenting dialogs. This "GUI-task" would need to be set to "run only when user is logged on" and have a trigged on ex. "at logon".

Obviously the 2 scripts have to communicate somehow (via a file, a REST api or whatever)

Upvotes: 5

Related Questions