Close an application window without terminating in Command Line - windows

Is there a command on the Windows terminal to close the window of an active application without actually killing the task/process?
What I'm looking for is something similar to clicking the 'X' button on the application window's name bar, or hitting Alt+F4 on it.
Any help would be greatly appreciated. Thanks!
I don't want the taskkill command because it terminates the process. I don't want it to terminate, say I want to close a Skype window so that it pops up in my Notification Tray on my Taskbar.

I couldn't find a specific command on the Windows terminal to do what I wanted, but I found this VBScript code online that did the trick for me.
set shell = createobject("wscript.shell")
shell.appactivate("Skype for Business")
shell.sendkeys "%{F4}"
This simulated an Alt+F4 keypress to Skype, which effectively closed the window and sent it to my Notification Tray.

Related

CMD set focus to application

Is there a way to set the focus to an already opened window using cmd/batch?
It should act just like clicking the task bar icon.
Or like double-clicking the window in Task-Manager.
I know there are many similar questions, but i couldn't find an answer to this "simple" task, I just can't imagine this is to be so difficult to do...
example:
I have Outlook opened somewhere in the background.
When executing the command, the open window should come to the front.
If no window is open, it should open a new one.
What i tried:
start outlook
-> this will always open a new window
start outlook /[non-existing command]
-> this is the only way i found to get the focus on an open window, followed by an error since it doesn't know the command, but Outlook does not open unless it's already running. An option might be, to tell Outlook not to do anything?

windows Cmd freezes and I have to click on window to coninue

I have a ruby script that displays it's progress via the cmd and completes in about 10 minutes. In the last few weeks the cmd seems to freeze and after 10 minutes when I click on the cmd window it then completes the script.
I have searched on forums and suggestions include: disable QuickEdit Mode & Insert Mode which I have done but this has not fixed the problem.
The platform is an azure windows server 2016 VM.
Could this problem be due to a recent windows update?
Thanks
If you are using the usual Windows Command Window, Ruby has no way of knowing that you have clicked into the Window, so it is unlikely that it is related to the code. However, Windows does block a command to write to the command window on certain circumstances, and if this happens, Ruby waits on, say, STDOUT.puts, until it is allowed to continue. Of course this applies not only to Ruby, but to any application writing to the command console.
The most typical situation, in which this occurs, is, if you (maybe accidentally) select with the mouse something in the console Window. The script running in the console is blocked. By clicking with the mouse inside the window, the selection is cancelled, and the program continues to run.

Restart Windows' explorer.exe via QProcess

At first, the Windows explorer.exe was closed and the desktop screen went black. My program needs to start explorer.exe. This is I tried:
QProcess process;
process.execute("explorer.exe");
The problem is this only pops up a new explorer window instead of reactivating the desktop explorer (turn the black screen back to desktop). It should behave just like when you run explorer.exe after you kill it in cmd or powershell.
Solution found:
QProcess::startDetached("explorer.exe"); //Wrong
QProcess::execute("C:\\Windows\\explorer.exe"); //Wrong
QProcess::startDetached("C:\\Windows\\explorer.exe"); //Right
If anyone knows why explorer.exe behaviour like this, please share it.

Run browser on background

I'm trying to open a browser with vbs program on background. My program code is this:
CreateObject("Wscript.Shell").Run "firefox.exe",0,True
The problem is that the window that opens isn't hidden. Also if I open any other program this way it runs on background eg. if I replace firefox.exe with notepad.exe. what's wrong? Thanks
Browsers often have many processes for UI and pages. It's likely the first firefox.exe only serves as a launcher, and it opens subsequent instances of firefox.exe that actually provides the UI. So unfortunately you can't hide the window with your current implementation.

Send keystrokes from vbscript to a CMD window

I run a batch file as part of Windows XP startup which executes continuously until Windows closes. It calls a VBScript file, which executes SendKeys "+{ESC}" (Shift+Esc). This gets picked up by 4t Tray Minimiser to send the CMD window to the system tray. Most times it works, but occasionally the CMD window stays visible.
Upon searching, various posts seem to suggest the .VBS file is losing focus or it's a timing problem. Some suggest AppActivate but I can't work out how to achieve what I want. Even the examples given for AppActivate seem like a lot of work.
Did you check the documentation? It's actually rather straightforward. You call AppActivate with the title (or part of the title) of the window you want to bring to the foreground, then run SendKeys to send keystrokes to the foreground window.
Set sh = CreateObject("WScript.Shell")
sh.AppActivate "window title"
sh.SendKeys "+{Esc}"

Resources