Filling in text box field in a Window

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?

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
if ($.KeyCode -eq "Enter")
write-host $pc_UsernameTextBox.Text;
write-host $pc_PasswordTextBox.Text;
#If you hit Escape on the form it exits
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"

#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"

#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"

#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

#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 = "

#Showing the form
$objForm.Topmost = $True
[void] $objForm.ShowDialog()
by sgarciacode at 2013-03-10 11:24:35