How to Provide Input to Applications with PowerShell

Something is useful automate an application task/setting from command line. From powershell  you can use .NET framework and using SendKeys to provide input to graphical applications.

Here a small example that open Notepad, type some text and open “Save as..” window:

# Load Assebly System.Windows.Forms  
[void] [System.Reflection.Assembly]::LoadWithPartialName(“‘System.Windows.Forms”)

# Load NotePad
& “$env:WINDIR\notepad.exe”

# Wait the application start for 1 sec 
Start-Sleep -m 1000

# Send keys
[System.Windows.Forms.SendKeys]::SendWait(“I'm wrinting something”)
[System.Windows.Forms.SendKeys]::SendWait(“Powered by PowerShell”)

# Open "Save As.." menu (Alt+f+s)

# Wait menu opening for 0.5 sec 
Start-Sleep -m 500



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s