Avatar of PeterdeB
PeterdeB
Flag 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.

Visual Basic Classic

Avatar of undefined
Last Comment
PeterdeB

8/22/2022 - Mon
PeterdeB

ASKER
Ps I tried this one as well:

WshShell.Run """" & App & """", 1, True
WScript.Sleep(200)
WshShell.SendKeys "%{F4}"    
ASKER CERTIFIED SOLUTION
Ravi Singh

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
PeterdeB

ASKER
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 :)
PeterdeB

ASKER
'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
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy