Close Win10 'Start Menu' if open using AHK? - windows

I've made a AHK script to keep an application open and focused as soon as Windows starts / logs in. I've since found though that WinActivate doesn't work in Windows 10 if the Start Menu is open. And apparently the last time "WinClose, Start Menu" worked was in WinXP.
Here's my code changed to use notepad so you can easily see what I'm trying to do (WinClose Start Menu step):
#WinActivateForce
FocusTimer = 3000 ;Time spent between refocusing on window (in milliseconds)
APP_TITLE = Untitled - Notepad ;Title of application window
APP_EXE = C:\Windows\System32\notepad.exe ;Application executable filepath
Sleep, %FocusTimer% ;Allows time for Windows to login and run other startup processes
While(TRUE) ;Infinite loop for program commands
{
Run, %APP_EXE% ;Opens application
Sleep, %FocusTimer% ;Allows time for previous action
While WinExist(APP_TITLE) ;Infinite loop for while application window is available
{
WinClose, Start Menu ;Closes Start Menu if open so as not to interrupt WinActivate command
WinActivate, %APP_TITLE% ;Commands focus on the application window
WinWaitActive, %APP_TITLE%, , 0 ;Waits for application window to have focus
Sleep, %FocusTimer% ;Wait timer before starting the loop again
}
Sleep, %FocusTimer% ;Allows clean-up time before starting the program commands again
}
I don't want to do anything drastic by disabling the Start Menu altogether. I just want to close it to remind the user that "this PC is only to run this application". It'll also alert the fact if randoms walk in and say "The Start Menu keeps closing???" If they want to interrupt the application then they have to manually pause the script via the system tray icon.
TIA

The Start Menu's title is no longer "Start Menu". This seems to work for me:
WinClose ahk_class Windows.UI.Core.CoreWindow ahk_exe SearchUI.exe
WinClose ahk_class Windows.UI.Core.CoreWindow ahk_exe StartMenuExperienceHost.exe ; Suggested by 0x464e
It will also close search and Cortana.

Related

Close Unwanted Mac Terminal Windows En-masse

As a system admin, I write/test/run a ton of shell scripts (typically from BBEdit). I rely on the BBEdit “Run in Terminal” drop-down menu a lot to quickly test run a script.
As a result, I end up with a ton of 'dead' (unwanted/expired) Terminal windows (i.e. executed script windows with “[Process completed]" displayed at the bottom).
Does anyone have a suggestion for how to clean-up all of these dead Terminal windows em-masse?
I can't blindly close ALL windows (or quit Teminal.app) because I have current SSH sessions running and other tasks in-progress. I only want to close the Terminal windows that have been executed via BBEdit and display '“[Process completed]'.
I can't set the Apple Terminal.app preference to do this for me (Terminal -> Preferences -> Settings -> Shell -> When the shell exits) because I generally want to examine the output returned before closing for QA purposes.
My goal is to manually run a script/command from time to time to clean-up all the Terminal windows on-demand as needed. Once I have a ton of confusing dead windows that I dont need Ill run it and then continue working in BBEdit as needed.
After a few hours of writing/troubleshooting/editing a script (or multiple scripts) I end up with dozens of dead Terminal windows - of which I manually close with a click and a Command + W. This gets tedious of course.
I have played around in AppleScript for something to bind to a shortcut or widget, but haven't found a solution as of yet.
Simple commands such as
tell application "Terminal" to close (get window 1)
aren't too helpful because I havent been able to determine which windows have an inactive state and which do not.
Thoughts? Any suggestions are appreciated!
Every "window" object in Terminal has a property named "processes", which is a list of the active processes for that window.
If the "processes" list is empty (in AppleScript terms, processes = {}), then you can safely close the window.
Therefore, an AppleScript like this should work:
tell application "Terminal"
set windowsICanClose to (every window whose processes = {})
repeat with windowToClose in windowsICanClose
close windowToClose
end repeat
end tell
You can save that as a script, put it in BBEdit's "Scripts" folder, assign it a keyboard equivalent if you like, and that should do the job.
It's very simple:
tell application "Terminal" to close (every window whose processes = {})
This will close every window of Terminal that has: [Process completed]
Just to be clear.. If e.g. you have a Terminal window open with multiple tabs, then tell application "Terminal" to close (every window whose processes = {}) only closes the tabs that have [Process completed] and not any other tab in that window. The window is only closed if the only tab of that window contains [Process completed]. That is to say, that is the result as tested under macOS High Sierra anyway.

Windows 10: command window does not close, but closes in Windows 7

i'm using windows 10 and trying to start an exe in diffrent folders sequentially. The idea is to use popen from subprocess and wait for the process to finish. The problem is, that the window does only close if I click on it or hit a key. On a windows 7 machine however the window is closing and subprocess.wait() finishes.
import os
import subprocess
for path in ["C:\tmp\", "C:\tmp2\"]:
os.chdir(path)
mywindow = subprocess.Popen(["my.exe",
#stdin=subprocess.PIPE,
#stdout=subprocess.PIPE,
#stderr=subprocess.PIPE,
#shell=True,
creationflags=subprocess.CREATE_NEW_CONSOLE,
env=dict(os.environ, **{"test":"AUTO"}))
mywindow.wait()
I used creationflags=subprocess.CREATE_NEW_CONSOLE, because I need to be able to start my.exe multiple times and be able to read the output on another console. But in some cases I want to wait for my process to end.
Update:
After eryksuns comment I'm pretty sure that this more of a windows problem than a python one.
On Windows 7 "my.exe" exits and wait() returns afterwards. On windows 10 however, I have to click somewhere on the screen or press any key, in order to close the console window "my.exe" opens. Afterwards the wait()returns. Disabeling the cmd quick edit mode had no effect.

Press enter to close a window in Batch

I'm playing a game and alongside the game .exe I also run another .exe that runs a personal program I'm developing (it records information that I can then monitor outside the game.)
One of the .exe's opens a cmd window, which I'd then like to immediately close at the end of the .bat.
Pressing enter manually will close the window, however, I don't know how to automate the enter keypress.
All I want to do is automate the pressing of the enter key after both the exes have been launched.
Should be simple to do I guess! but looked around for a while and can't find a solution.
Thanks.
the code for my very very basic batch:
start "" "E:\World of Warcraft\Wow-64.exe"
start "" "C:\Users\Kek\Desktop\New folder\DocumentAll.exe"

Use NirCmd to pass a key press into XP virtualpc

I am converting a VirtualBox XP image to Virtual PC. When booting up, the XP image is going through the Found New Hardware Wizard.
At this point in the process, VirtualPC does NOT pass in the mouse or keyboard. So I am using a script to run nircmd.
The first thing my script does is clears the Reactivation Message by waiting 10 seconds, sending a Tab key press and an Enter key press.
This followed by a 60 second wait for the New Hardware wizard to appear.
Then I move the cursor onto the Next button.
So far the first five entries work correctly.
(I wait one second and send a left mouse click to get the focus.)
Then try to get the hardware wizard to continue.
None of my attempts work.
Left mouse click - nothing happens.
Enter key press - nothing happens.
send key press of Alt+n - nothing happens.
Left mouse double-click - nothing happens.
So I wait 30 seconds and shutdown - That works.
I am open to suggestions.
thank you,
chuck
Script:
nircmdc wait 10000
nircmdc sendkeypress tab
nircmdc sendkeypress enter
nircmdc wait 60000
nircmdc setcursor 390 390
nircmdc wait 1000
nircmdc sendmouse left click
nircmdc wait 1000
nircmdc sendmouse left click
nircmdc wait 1000
nircmdc sendkey enter press
nircmdc wait 1000
nircmdc sendkeypress alt+n
nircmdc wait 1000
nircmdc sendmouse left dblclick
nircmdc wait 30000
nircmdc exitwin shutdown
Ok, here's what happened.
It seems that my script would only run part way when set to run as a StartUp script from the GPO.
When I added the appropriate items to the script and ran that from the user..\startup location, it worked.
I am not sure why, after the user logon was processed, that the move cursor would work, but not the other steps.
Anyways, if someone else runs into this, this is what I used.
Now someone with higher power than I will need to close this one.
thanks,
chuck

How to close Windows Explorer from CMD

Is it possible to close Windows Explorer from CMD? I have a batch that does this: it will change directory, open explorer in this folder, than run a program. After the user closes the program the batch should close the explorer (or all explorers opened), continue on next folder (cd folder), run the same program in this folder and so on. Till the last folder is processed.
Close the explorer windows by killing the explorer process (note that this may do more than just kill the windows, but it will definitely do that):
for example, use win+r and try this
cmd /c "taskkill /f /im explorer.exe && start explorer"
If you kill explorer without restarting it, use Ctrl+shift+Esc to pull up the taskmanager and start a new task "explorer".
Not from a batch file unless you want to write your own command line application that opens up a windows explorer window, and (this is the key part) somehow knows the window handle of that explorer window, so it can post a WM_CLOSE message to it, which basically simulates someone closing that window.
How you would determine "all the explorer windows that got opened" would be that instead of just starting explorer.exe instances from a command line you would do it from your own application.
I think that determining the window handle (HWND in win32 api terms) and posting a close message would be better than trying to track process handles and terminating explorer process instances, since that could cause some side effects beyond those that you'd want.

Resources