Filling in text box field in a Window

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 5 years, 7 months ago.

  • Author
    Posts
  • #6050

    by sgarciacode at 2013-03-06 13:51:59

    Hello Everyone,

    I want to know if it is possible for powershell to open up a *.dtt window and fill in the two text fields that it requires and click the send button? Is there some way of finding out what the hadles to each component of the window are so that you can select and act on each one? Also what other forms of UI manipulation is powershell capable of?

    Thanks,

    by simark at 2013-03-07 05:24:39

    Hi sgarciacode,

    Maybe I have a partial answer for your second question: [quote] what other forms of UI manipulation is powershell capable of[/quote]

    #Creat a login form that returns the username and password

    #Load winform assemblies
    [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
    [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

    #Creating the form
    $objForm = New-Object System.Windows.Forms.Form
    $objForm.Text = "My winForm"
    $objForm.Size = New-Object System.Drawing.Size(250,220)
    $objForm.StartPosition = "CenterScreen"
    $objForm.KeyPreview = $True

    #If you hit Enter on the form it gets the Textbox values
    $objForm.Add_KeyDown(
    {
    if ($_.KeyCode -eq "Enter")
    {
    write-host $pc_UsernameTextBox.Text;
    write-host $pc_PasswordTextBox.Text;
    $objForm.Close()
    }
    })
    #If you hit Escape on the form it exits
    $objForm.Add_KeyDown(
    {
    if ($_.KeyCode -eq "Escape") {$objForm.Close()}
    })

    #Adding Username Label
    $Username_Label = New-Object System.Windows.Forms.Label
    $Username_Label.Location = New-Object System.Drawing.Size(110,10)
    $Username_Label.Size = New-Object System.Drawing.Size(60,20)
    $Username_Label.Text = "Username"
    $Username_Label.ForeColor = "Red"
    $objForm.Controls.Add($Username_Label)

    #Adding Password label
    $Password_Label = New-Object System.Windows.Forms.Label
    $Password_Label.Location = New-Object System.Drawing.Size(170,10)
    $Password_Label.Size = New-Object System.Drawing.Size(60,20)
    $Password_Label.Text = "Password"
    $Password_Label.ForeColor = "Red"
    $objForm.Controls.Add($Password_Label)
    $objForm.Controls.Add($Host_Label)

    #pc Label
    $pc_Label = New-Object System.Windows.Forms.Label
    $pc_Label.Location = New-Object System.Drawing.Size(10,50)
    $pc_Label.Size = New-Object System.Drawing.Size(100,20)
    $pc_Label.Text = "PC"
    $objForm.Controls.Add($pc_Label)

    #pc_Username textbox
    $pc_UsernameTextBox = New-Object System.Windows.Forms.TextBox
    $pc_UsernameTextBox.Location = New-Object System.Drawing.Size(110,50)
    $pc_UsernameTextBox.Size = New-Object System.Drawing.Size(60,20)
    $pc_UsernameTextBox.Text = "yourname"
    $pc_UsernameTextBox.Enabled = $true
    $objForm.Controls.Add($pc_UsernameTextBox)

    #pc_Password textbox
    $pc_PasswordTextBox = New-Object System.Windows.Forms.TextBox
    $pc_PasswordTextBox.Location = New-Object System.Drawing.Size(170,50)
    $pc_PasswordTextBox.Size = New-Object System.Drawing.Size(60,20)
    $pc_PasswordTextBox.PasswordChar = "*"
    $objForm.Controls.Add($pc_PasswordTextBox)

    #Showing the form
    $objForm.Topmost = $True
    $objForm.Add_Shown({$objForm.Activate()})
    [void] $objForm.ShowDialog()

    by sgarciacode at 2013-03-10 11:24:35

    Thanks!

You must be logged in to reply to this topic.