Asked — Edited
Quick question. As the title suggests, after opening a program or file in Windows 8 using the EXEC() command (e.g, opening a picture), how can you close that program or file using the execute command?
Upgrade to ARC Pro
ARC Early Access will give you immediate updates and new features needed to unleash your robot's potential!
process.exe would be the name of the exe that you want to kill.
This is a post on another forum that I found about a similar topic.
"The proper way to close/exit a program ultimately depends upon the software. However, generally the best practice is for Windows programs to close whenever they receive the WM_CLOSE message. Properly releasing memory and closing handles. There are other messages that can signal the close of the application, but it is up to the author of the software how each message is handled.
taskkill /IM process.exe
taskkill sends the WM_CLOSE message and it is then up to the application whether to properly close. You may also want to use the /T option to also signal child processes.
Only use the /F option if you want to force the termination of the process.
WM_CLOSE vs SC_CLOSE
How to Gracefully Terminate a Process
How To Terminate an Application "Cleanly" in Win32
Other options would include sending the Alt+F4 keys, using PowerShell, or 3rd party applications.
Update to Updated Question
Ignore, the errors. Chrome generates many processes. The errors are caused when an process does not acknowledge the WM_CLOSE message that TASKKILL sends. Only processes with a message loop will be able to receive the message, therefore, the processes that do not have a message loop will generate that error. Most likely, these processes are the chrome extensions and plugins.
To hide the errors capture the output
taskkill /IM chrome.exe >nul
Summary: TASKKILL is the proper way via command line to close applications per its WM_CLOSE implementation and the Microsoft KB Article that I have linked."
I gave it a shot. When I open the CMD prompt window and type"TaskList" the list shows shows what's running and had success using "TaskKill" closing my web browser, but I can't seem to find the correct image name or PID code for things like Windows photo viewer or video player which are open. They are more than likely there but don't recognise the correct image name.
Haven't tried your script yet.
What is the "PhotosApp" for? Is it for the "Windows Photo viewer" app or the "Photos" app? Either way, even with the script you just supplied David, it opens the photo, but doesn't close it (although I do see the CMD window flash up very quickly after the 2 second sleep).
Open the photo.
From a command line try this
taskkill /F /IM PhotosApp.exe
Tell me what the next line says.
Then, try this
taskkill /F /IM dllhost.exe
Tell me what the next line says.
I am looking to see if a line like this shows up
"SUCCESS: The process "PhotosApp.exe" with PID 8312 has been terminated."
"SUCCESS: The process "dllhost.exe" with PID 7568 has been terminated."
"SUCCSESS: Sent termination signal to the process with PID 6464.
so all good there.
But within ARC, it's a different matter. Running the script opens the photo, sleeps for 2 seconds, then I see the CMD window flash once, but photo remains open with the script console saying "Done".
That's 2 for 2 David. Once again, thanks very much for your help. Most grateful.