Powershell – Prevent Windows PowerShell console from flashing up

batch-filepowershell

CustomApp is registered with a URI Scheme in Windows 10 so it launches when Chrome browser visits CustomApp://userid@departmentid

Computer\HKEY_CLASSES_ROOT\CustomApp\shell\open\command

C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -File "C:\Program Files\CustomApp\bin\launch-customapp.ps1" -uri "%1"

Works great for launching the CustomApp but the blue Windows PowerShell console flashes up briefly during execution. How can I prevent it from popping up?

I've tried these parameters but the console window still flashes up.

-WindowStyle Hidden
-NonInteractive
-NoLogo

Best Answer

I found the best method is to use VBScript as -WindowStyle Hidden will always briefly popup with PowerShell.

Copy the below into a text file with a vbs file extension, edit the referenced ps1 file and use this to script to launch your PowerShell script.

CreateObject("Wscript.Shell").Run """%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe"" -NoProfile -ExecutionPolicy Bypass -File ""C:\Script.ps1""",0,True