orbisuser
asked on
How to open then close a window/app/object run by powershell script.
I'm trying to use a batch file run via GPO to open a powershell script at login that will display a splash image. Script code is here:
# .Net methods for hiding/showing the console in the background
Add-Type -Name Window -Namespace Console -MemberDefinition '
[DllImport("Kernel32.dll") ]
public static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, Int32 nCmdShow);
'
function Hide-Console
{
$consolePtr = [Console.Window]::GetConso leWindow()
#0 hide
[Console.Window]::ShowWind ow($consol ePtr, 0)
}
Hide-Console
# Loosely based on http://www.vistax64.com/powershell/202216-display-image-powershell.html
[void][reflection.assembly ]::LoadWit hPartialNa me("System .Windows.F orms")
$file = (get-item 'C:\Users\Public\Pictures\ Sample Pictures\Chrysanthemum.jpg ')
#$file = (get-item "c:\image.jpg")
$img = [System.Drawing.Image]::Fr omfile($fi le);
# This tip from http://stackoverflow.com/questions/3358372/windows-forms-look-different-in-powershell-and-powershell-ise-why/3359274#3359274
[System.Windows.Forms.Appl ication]:: EnableVisu alStyles() ;
$form = new-object Windows.Forms.Form
$form.Text = "I'm obv not a programmer"
$form.Width = $img.Size.Width;
$form.Height = $img.Size.Height;
$pictureBox = new-object Windows.Forms.PictureBox
$pictureBox.Width = $img.Size.Width;
$pictureBox.Height = $img.Size.Height;
$pictureBox.Image = $img;
$form.controls.add($pictur eBox)
$form.Add_Shown( { $form.Activate() } )
$form.ShowDialog()
#$form.Show();
The script creates an object then displays the image in it. I've added some code to the beginning that will hide the powershell console window so that only the image object shows.
Users can close the window, but it would be better if I could have the image displayed and then close after 15 seconds or so. It would be REALLY cool if the object title bar and window options (min/max/close) were not available and they'd have to endure whatever image I throw up there. Any advice would be greatly appreciated.
# .Net methods for hiding/showing the console in the background
Add-Type -Name Window -Namespace Console -MemberDefinition '
[DllImport("Kernel32.dll")
public static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, Int32 nCmdShow);
'
function Hide-Console
{
$consolePtr = [Console.Window]::GetConso
#0 hide
[Console.Window]::ShowWind
}
Hide-Console
# Loosely based on http://www.vistax64.com/powershell/202216-display-image-powershell.html
[void][reflection.assembly
$file = (get-item 'C:\Users\Public\Pictures\
#$file = (get-item "c:\image.jpg")
$img = [System.Drawing.Image]::Fr
# This tip from http://stackoverflow.com/questions/3358372/windows-forms-look-different-in-powershell-and-powershell-ise-why/3359274#3359274
[System.Windows.Forms.Appl
$form = new-object Windows.Forms.Form
$form.Text = "I'm obv not a programmer"
$form.Width = $img.Size.Width;
$form.Height = $img.Size.Height;
$pictureBox = new-object Windows.Forms.PictureBox
$pictureBox.Width = $img.Size.Width;
$pictureBox.Height = $img.Size.Height;
$pictureBox.Image = $img;
$form.controls.add($pictur
$form.Add_Shown( { $form.Activate() } )
$form.ShowDialog()
#$form.Show();
The script creates an object then displays the image in it. I've added some code to the beginning that will hide the powershell console window so that only the image object shows.
Users can close the window, but it would be better if I could have the image displayed and then close after 15 seconds or so. It would be REALLY cool if the object title bar and window options (min/max/close) were not available and they'd have to endure whatever image I throw up there. Any advice would be greatly appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Expert wrote code that was much better than the stuff I googled and slapped together. TYVM.
ASKER