Link to home
Start Free TrialLog in
Avatar of PeterdeB
PeterdeBFlag for Netherlands

asked on

How do I launch an application and close it after a few seconds?

Hi my dear friends!

I would like to launch an application and close it after a few seconds....now this code seemed to work. Only after editing the wrong file ( I was editing a backup file while testing the original) it stopped working. Note: launching the application is no problem, only closing down is a problem. I tried several sleep arguments but without success. I just can't close the application just like I did a few hours ago.

'Beginning of code

Set WshShell = WScript.CreateObject("WScript.Shell")

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Launch the application
' Wait for the application
' Send ALT F4 to close the application
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
WshShell.Run """" & App & """", 1, True
WScript.Sleep 200
WshShell.SendKeys "%{F4}"    

'End of all hope :)

Kind regards,

Paul

Ps working samples please! And if you need more info, please ask. I will be firing some more questions about this issue so that is why I do not post all the code at once.

Avatar of PeterdeB
PeterdeB
Flag of Netherlands image

ASKER

Ps I tried this one as well:

WshShell.Run """" & App & """", 1, True
WScript.Sleep(200)
WshShell.SendKeys "%{F4}"    
ASKER CERTIFIED SOLUTION
Avatar of Ravi Singh
Ravi Singh
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Zephyr,

True, this works. However when I ran my script earlier today, the param was also set to True yet it closed with this code.

I need the param to be True since I want to know whether the application ran and closed without an error.

Kind regards,

Paul

Ps The points are yours :)
'However when I ran my script earlier today, the param was also set to True yet it closed with this code.'

> this was not the case ofcourse, since I was editing one file and testing another. So much for being stubborn :)

Regards Paul