1
votes

I have a PowerShell script which implents a small update routine. It should run in background, but without closing an active program, which runs in fullscreen.

I tried to set up a scheduled task in the GUI with

powershell -File pathtofile -NonInteractive -NoLogo -WindowStyle hidden

but the console window still pops up. Is there any way to prevent this?

Alternatively, is there a possibility to get a minimized window back to fullscreen?

2
What are you using a scheduled task for here? If you have a main script and want to run something in the background while the main script keeps running in the foreground: use a background job. That's what they were made for. - Ansgar Wiechers
it's not a script that is running in foreground, it's a standard windows program - leflic
Then how does it relate to the script you're trying to run in the background? And why would you need to close the active program to be able to run the script? - Ansgar Wiechers
It's the update routine for that program. I don't want to close the active program, the script should run in the background without minimizing the program. - leflic
A scheduled task that is configured to run whether the user is logged in or not should not display a console window. And you should be able to restore a minimized program to its previous state simply by clicking on the taskbar icon. - Ansgar Wiechers

2 Answers

1
votes

There isn't any way AFAIK to move or change the state of a window that is already open so restoring a minimised window probably isn't feasible.

The reason your PS UI is still showing is because of the order of the parameters. Try these two commands:

PowerShell.exe -Command ping www.google.com -WindowStyle Hidden
PowerShell.exe -WindowStyle Hidden -Command ping www.google.com

The second command correctly hides the PowerShell window while the first one does not, however even working correctly it flashes up briefly before hiding so I don't know if this will still minimise your fullscreen application.

1
votes

Create a simple VBScript that calls your powershell script. Then in Windows Task scheduler you can call the VBScript using a "Start a program" action. I was not able to find a way to hide the powershell window when trying to launch the powershell script directly through Task Scheduler (i.e. without a wrapper VBScript).

Here is an example of a VBScript that worked for me, taken from here:

Dim shell,command
command = "powershell.exe -nologo -File D:\myscript.ps1"
Set shell = CreateObject("WScript.Shell")
shell.Run command,0