wpfpowershellscheduled-taskswindows-server

Powershell WPF GUI not visible as scheduled task


I am writing a PowerShell script that displays a WPF GUI to the user. The Task Scheduler is supposed to run this script every day at a certain time.

The script works fine when I start it manually, but when I schedule it with the Task Scheduler the GUI won't show. The task will enter 'running' state for about half a minute, then exit without errors. During this time it shows up as background process in the Task Manager.

The task is run as SYSTEM user and starts a powershell.exe with these arguments:

-NonInteractive -NoProfile -Command "& { C:\path\to\script.ps1 }"

At first I was getting the error described in this blog post and the provided instructions fixed it. Now I only see in that the SYSTEM user was authenticated and that a Powershell was invoked with the arguments from the task.

Can anybody offer any advice on how to make the WPF window visible or what the cause for this error may be?

I am running PowerShell v3 with .NET version 3.5. I have tested this on Windows Server 2016 and 2012.

Powershell script: https://pastebin.com/xLw76arr

Exported Task XML: https://pastebin.com/JRTkeFSA


Solution

  • Could you show the code used to display the WPF form ?

    You should use a logged user to see the WPF form during execution.