Microsoft, Powershell, Send Key(s)

Posted on 2007-08-07
Medium Priority
Last Modified: 2013-11-05
How can I do scripting commands like "Send Key(s)" or "Activate Window" using PowerShell?
Does this require the use of the Net Framework?
What is the best way to implement this type of scripting?
Question by:wsfindlater
LVL 18

Accepted Solution

BSonPosh earned 2000 total points
ID: 19738851
You can do create the Wscritp.Shell com object like this

$myshell = New-Object -com "Wscript.Shell"

To see Methods and Properties you have access to
$myshell | get-members
AppActivate              Method
CreateShortcut           Method
Exec                     Method
ExpandEnvironmentStrings Method
LogEvent                 Method
Popup                    Method
RegDelete                Method
RegRead                  Method
RegWrite                 Method
Run                      Method
SendKeys                 Method
Environment              ParameterizedProperty
CurrentDirectory         Property
SpecialFolders           Property

So to activate Notepad and send text do
PS> $myshell.AppActivate("notepad");$myshell.sendkeys("Hello")

You have to do these as two command seperated by ";" because you would steal focus if you did this
PS> $myshell.AppActivate("notepad")
PS> $myshell.sendkeys("Hello")

Author Comment

ID: 19739225

Wow! Thank-you very much. Now I can do everything with PowerShell.

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses
Course of the Month16 days, 6 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question