1

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?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
leflic
  • 49
  • 1
  • 2
  • 10
  • 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](https://technet.microsoft.com/en-us/library/dd878288.aspx). That's what they were made for. – Ansgar Wiechers Jan 08 '16 at 16:50
  • it's not a script that is running in foreground, it's a standard windows program – leflic Jan 08 '16 at 16:54
  • 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 Jan 08 '16 at 16:56
  • 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 Jan 08 '16 at 16:58
  • 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 Jan 08 '16 at 17:09
  • See [How do I set a Windows scheduled task to run in the background](http://stackoverflow.com/questions/6568736/how-do-i-set-a-windows-scheduled-task-to-run-in-the-background) – Rodrigo Murillo Jan 08 '16 at 17:32
  • Why won't you use `Register-ScheduledJob` along with `New-JobTrigger` Using these, you can run a background job without any GUI window. – user4317867 Jan 08 '16 at 17:33
  • Here is the solution https://superuser.com/a/1038142/106079 – BBK Jun 26 '18 at 22:11

2 Answers2

1

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.

Deadly-Bagel
  • 1,612
  • 1
  • 9
  • 21
1

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
jwenz723
  • 349
  • 2
  • 4