Ensuring Dialog is Focused

Welcome Forums General PowerShell Q&A Ensuring Dialog is Focused

This topic contains 2 replies, has 3 voices, and was last updated by

 
Participant
1 year, 10 months ago.

  • Author
    Posts
  • #60697

    Participant
    Points: 0
    Rank: Member

    Hello,

    Completely new to PS but have the following startup script to ask whether I want a specific application started. The issue I am having is that this dialog is never in focus, so I can't simply hit enter to launch. I have tried a few things online including delaying the script by a few seconds at start, but nothing I do seems to force this window to be focused. Any ideas?

    Thanks
    t

  • #60775

    Participant
    Points: 160
    Helping Hand
    Rank: Participant

    You should look at creating an actual GUI from XAML or .NET Forms with Powershell so that you can control the actual Window. If you create the window you can set properties like TopMost and use methods like Activate() and Focus(). Open Form > Set TopMost > Activate form > Focus on "Submit" button so you can press enter. Just do some searches on Powershell GUI and look at tools like Powershell Studio from Sapien, Visual Studio, ISE Steriods to expedite form creation. You should be able to find something with a little research that has a couple of buttons you can update to your needs.

  • #60913

    Participant
    Points: 21
    Rank: Member

    You only have two options therefore the switch isn't needed.

    [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
    $prompt = [System.Windows.Forms.MessageBox]::Show(
    
    "
    Install something.
    
    ", 
    
    "Question:", 
    
    [System.Windows.Forms.MessageBoxButtons]::YesNo, 
    [System.Windows.Forms.MessageBoxIcon]::Information,
    [System.Windows.Forms.MessageBoxDefaultButton]::Button1,   [System.Windows.Forms.MessageBoxOptions]::ServiceNotification
    )
    
    
    if($prompt -eq 'yes'){ 'begin installation' }else {'you chose no'}
    
    

The topic ‘Ensuring Dialog is Focused’ is closed to new replies.