4

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?

Frode F.
  • 52,376
  • 9
  • 98
  • 114
Ronen
  • 71
  • 1
  • 5
  • What happens if you trigger the Scheduled Task "at logon"? – Johan de Haan Mar 09 '16 at 14:24
  • Under what context are you running the scheduled task? If you're running it as SYSTEM, for example, it's running under a different context and you won't be able to interactively see any windows popping up. – Adam Bertram Mar 09 '16 at 15:32

1 Answers1

4

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)

ndemou
  • 4,691
  • 2
  • 30
  • 33
Frode F.
  • 52,376
  • 9
  • 98
  • 114