Hide blank console window in whole Powershell script GUI?

I created a very simple Powershell script with a WinForms GUI. Everything works as intended, but when I run the .ps1 script with PowerShell, an empty window appears with an empty console first, and then the GUI is displayed.

In any case, so that the console window disappears?

Regards

+3
source share
3 answers

I wrote a short article on this topic (sorry in French) a year ago.

Here is a general solution using a small VBS script to launch PowerShell by hiding its window (the trick is in the last one , 0 ).

Set Args = Wscript.Arguments
'MsgBox  "Chemin LDAP: " & Args(0)
'MsgBox  "Classe: " & Args(1)

Set objShell = CreateObject("Wscript.Shell")
objShell.Run "c:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -nologo -Noninteractive -file c:\SlxRH\RhModif.ps1 " & chr(34) & Args(0) & chr(34) , 0

PowerShell slxPShell2.EXE.

+2

, . :

Set objShell = CreateObject("WScript.Shell")

objShell.Run "CMD /C START /B " & objShell.ExpandEnvironmentStrings("%SystemRoot%") & "\System32\WindowsPowerShell\v1.0\powershell.exe -file " & "YourScript.ps1", 0, False

Set objShell = Nothing

, .

0

:

  1. Winforms ScriptOne.ps1
  2. LaunchScriptOne.ps1 :

powershell.exe -WindowStyle Hidden -File "C:\path\to\ScriptOne.ps1".

: powershell Winform

, - . , , , - , idk.

0

All Articles