I build a small tool with powershell and i open it through a batch-file. Batch file has the following content :
powershell -file "D:\scripts\Powershell\xxx.ps1"
Now it opens my tool but always displays the command prompt in background. I want the CMD to be hidden after running my file.
How to achieve that? I tried -hidden
but then my programm is hidden :D
Thanks
Try using the START
utility in your batch file, it will launch the program in a new window and allow the batch's cmd
window to exit in the background.
START powershell -file "D:\scripts\Powershell\xxx.ps1"
Be aware START
exhibits [potentially] unexpected behavior when the first parameter contains double quotes.
If you're using GUI elements, or external applications, and you want to hide Powershell's window, but not the GUI, try the following:
START powershell -WindowStyle Hidden "D:\scripts\Powershell\xxx.ps1"
Here's an example of how I've used batch in tandem with PowerShell GUI:
Contents of C:\call.cmd:
START "" powershell -NoLogo -WindowStyle Hidden "C:\gui.ps1"
Contents of C:\gui.ps1:
# VB Assembly GUI example
Add-Type -AssemblyName Microsoft.VisualBasic
[Microsoft.VisualBasic.Interaction]::MsgBox(
"Do you like VB in PowerShell?",
[Microsoft.VisualBasic.MsgBoxStyle]::YesNo,
"Hello"
)
# Windows Forms GUI example
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.MessageBox]::Show(
"Do you like Windows Forms?",
"Hello",
[System.Windows.Forms.MessageBoxButtons]::YesNo
)
# External app GUI example
& notepad.exe
Running the call.cmd
batch will use START
to launch PowerShell [exiting cmd
] and PowerShell will hide its window, but otherwise display the GUI elements executed from the PS1 file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With