OK guys - first post here and I've stumbled upon this page through a link from a link from a link, so i apologize if I've not conformed to any posting rules. However,
Ive created a little tool to use at work, various functions including calling Active directory and doing various searches in there, finding computer names and IP's, then calling an instance of Ultra VNC to remote into that computer etc etc.... all pretty irreverent at the moment.
What my problem is, I programmed a nice GUI front end to it, which loads a $form with all the $buttons $textbox's etc in there, but its ALWAYS on top. SO if i click out of the window area, the form stays in front of everything. When i call my VNC function, or i click a button that access the C:\ via the $(dollar) share... the windows always lad behind the powershell GUI.
The way im calling my Gui at the moment, is by creating a shortcut to the script, and running the powershell as hidden (C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -windowstyle hidden & C:\Users\c<myusername>\docs\Powershell_scripts\find_user_gui.ps1)
That shortcut pulls in the .ps1 file, but hides the powershell console, and just shows my GUI, but the same thing happens even if i right click the .ps1 and "run with powershell" in the context menu
i wont include all the code, as theres a butt load of code in there, the main form is:
$Form = New-Object System.Windows.Forms.Form
$Form.Text = "Find User / Client Tool"
$Form.Size = New-Object System.Drawing.Size(900,800)
$Form.MaximizeBox = $false
$Form.backcolor = [System.Drawing.Color]::ghostwhite
$Form.StartPosition = "CenterScreen"
$Form.KeyPreview = $True
$Form.Add_KeyDown({if ($_.KeyCode -eq "Enter")
{$x=$ListBox.SelectedItem;}})
$Form.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$Form.Close()}})