opening a windows exe and need to select the messagebox default value

rated by 0 users
Not Answered This post has 0 verified answers | 7 Replies | 2 Followers

Not Ranked
7 Posts
muralierd posted on 04-24-2012 3:03 AM

Hi i have a requirement that i need to open a windows exe from powershell and that exe is having some messageboxes and it expects the user to select the options like ok or cancel.

i am doing some automation script so there is no user interventions. can u tell me how can i achieve this. if i run the ps1 file then how to send the messagebox's options from powershell.




All Replies

Top 25 Contributor
287 Posts
Top Contributor

I'm not sure if I undestand your question..

I assume this exe you are talking about is not an installer or if it's there are no silent switches right?

I'm not sure if you want to create message boxes or if you want to automatically supply input to the message boxes..

You can create message boxes like this:

$msg = New-Object -ComObject Wscript.Shell


And you can pass input like this:

$input = New-Object -ComObject Wscript.Shell


Not Ranked
7 Posts

hi first thanks for your replay. this is my first post in my past 6 years. 

Here is the situation

i am doing automation of deploying from powershell. 

i have custom created exe maybe from (windows application from dot net) 

i need to start that exe file from powershell, and when you run the exe file it is asking some input like "do you want to run this exe under debug mode" and the options are "Yes" and "No" after that it is asking someother question "Do you want to process..." and the options are same "OK" and "cancel".

My problem is i am using the start-process cmdlet to start the custom exe and how to pass the values for those messageboxes which is created inside the exe file.

for your information the exe doesn't have any parameter. I believe inside the code logic of that exe the messagebox was written.


if you have any doubt on the above situation then please let me know

here is the code 


start-process $filename 



Murali M


Top 25 Contributor
287 Posts
Top Contributor

Ok. Now I understand.

So as I said you can send keys to asnwer those questions.. But no interference can happen during the execution of the application and the sendkeys otherwise the keys sent would get lost.

When you run the application and get the first message box, any of the input boxes (eg. yes, no, cancel) are selected?

Also any of them have shortcuts? Like one letter is underlined so you can press alt + the letter?

Not Ranked
7 Posts

yes first messagebox got a selection under OK 

and the second messagebox got a selection under YES(if i press Y then the yes button got selected)

if you could send me the script, in which line i need to write the send keys whether before calling the start-process or after. This could be very helpful for me.


Murali M

Top 10 Contributor
640 Posts

So that you're aware, this isn't something PowerShell can do natively. It isn't designed to automate a GUI interface.

You can probably get it to do something for you... but it's going to be a hack. VBScript, with its SendKeys method, or AutoIt, a language intended for this sort of work, would be far more appropriate to the task. Both will let you do this much more easily, and will operate more consistently in this scenario.

If you really want to do this in PowerShell, look at That's a free add-in for PowerShell that lets you select a window and send key presses to it. Again, I think AutoIt would be a more appropriate solution to the task, but this should at least give you an option from within PowerShell.

Top 25 Contributor
287 Posts
Top Contributor

Yes, Don is right. AutoIt would be the recommended solution here. You have to learn it though.

If you still want to give the Poweshell SendKeys a try you can do something like:

$shell = New-Object -COMObject Wscript.Shell


Start-Sleep(5) #It waits 5 seconds for your program to pop up. Change it to your requirements.

#Then if you need to send just a "Enter" you can do:


#If you need to send Alt + Y you can do:


I hope you understand this.. and remember that nothing can happen between the execution of the program and the SendKeys otherwise the keys will go somewhere else.

Not Ranked
7 Posts

thanks for your help. it worked fine for me.

Page 1 of 1 (8 items) | RSS
Copyright 2012 All rights reserved.