Hi All,
I have a simple powershell form that is working fine and I am opening that from a batch file and this is also working. My batch file is like this:
@echo off
PowerShell.exe -executionpolicy bypass -Command “start-process ‘powershell.exe’ '-Command “”.\test.ps1”’ -WindowStyle Hidden -credential “org\itd412” -passthru"
exit/B
it works fine without the -WindowStyle Hidden parameter but as soon as I use this parameter it does not open the form. The problem is that without the parameter it open a powershell console window in the back ground of the form. I am going crazy with this. Below is my form code:
Add-Type -AssemblyName System.Windows.Forms
Create form
$form = New-Object System.Windows.Forms.Form
$form.Text = “My Form”
$form.Size = New-Object System.Drawing.Size(600,500)
$form.StartPosition = “CenterScreen”
Create label and textbox for computer name input
$lblComputerName = New-Object System.Windows.Forms.Label
$lblComputerName.Location = New-Object System.Drawing.Point(10,10)
$lblComputerName.Text = “Computer Name:”
$form.Controls.Add($lblComputerName)
$txtComputerName = New-Object System.Windows.Forms.TextBox
$txtComputerName.Location = New-Object System.Drawing.Point(120,10)
$txtComputerName.Size = New-Object System.Drawing.Size(150,20)
$form.Controls.Add($txtComputerName)
Create connect button
$btnConnect = New-Object System.Windows.Forms.Button
$btnConnect.Location = New-Object System.Drawing.Point(10,50)
$btnConnect.Text = “Connect”
$form.Controls.Add($btnConnect)
Create disconnect button
$btnDisconnect = New-Object System.Windows.Forms.Button
$btnDisconnect.Location = New-Object System.Drawing.Point(90,50)
$btnDisconnect.Text = “Disconnect”
$form.Controls.Add($btnDisconnect)
Create display panel (RichTextBox)
$displayPanel = New-Object System.Windows.Forms.RichTextBox
$displayPanel.Location = New-Object System.Drawing.Point(10,210)
$displayPanel.Size = New-Object System.Drawing.Size(580,500)
$displayPanel.ScrollBars = “Both”
$displayPanel.WordWrap = $false
$displayPanel.Font = New-Object System.Drawing.Font(“Lucida Console”, 9)
$form.Controls.Add($displayPanel)
Show the form
$form.ShowDialog() | Out-Null