2

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

3 Answers 3

2

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

  • Why using SYSTEM account ?
  • Why using the -NonInteractive parameter of powershell.exe ?

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

Sign up to request clarification or add additional context in comments.

2 Comments

I tried running it with my account, but it didn't work either. I don't want the user to use the powershell for anything else, beside showing the GUI.
i got it to run by setting the 'Run only when is logged on' and using my account. I'll mark you as answer.
0

PowerShell.exe doesn't load the WPF assemblies. You need to force load the assemblies in the script:

Add-Type –AssemblyName PresentationFramework
Add-Type –AssemblyName PresentationCore
Add-Type –AssemblyName WindowsBase

2 Comments

Can you provide your full script please?
here's the script that is supposed to run pastebin.com/xLw76arr .
0

i read somewhere that when a script is run as scheduled task, it works in non-interactive mode. Therefore, it has not shown any errors in your case, it just does not display GUI. I witnessed it myself when i was also trying to make loginForm appear when event is triggered, but i failed many times and then read about this concept

1 Comment

This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.