Shutdown a program which constanly changes window name with AutoHotKey? - autohotkey

I've recently started creating some simple scripts with autoHotKey, and I'd like to know if it is possible to close Spotify, which changes window title for every song.
I've tried with
Process, Close, Spotify
but it doesn't work unfortunately.

The following code snippet works for me:
while(Winexist("ahk_exe Spotify.exe"))
WinClose
Spotify is weird in that it appears to create many processes of itself when launched,
and that when you run a command like WinClose, ahk_exe Spotify.exe once, it does not immediately close the program (you can still use and interact with the GUI, but if you attempt to move the window by dragging the top bar, Spotify crashes).
However, if you spam that command over and over again, Spotify eventually closes as intended. So, in order to deal with this, let's create a program such that while there still remain Spotify processes, close Spotify Processes. Then, once there are no Spotify processes remaining, stop trying to close Spotify.

Related

How to immunise my antiprocrastination script against logout and shutdown?

I'm trying to build a script in autohotkey which will make it annoying for myself and fellow users of the flashcard program Anki from quitting midway through a study session.
So far I have written the following
InputBox, TimeMin, ATTENTION, Enter how long would you like to commit to answering flashcards in minutes.
TimeMili:=TimeMin*60*1000
SetTimer, Meh, %TimeMili%
a:=0
While a < 1
{
IfWinActive User 1 - Anki
{
MouseMove,1298, 981
WinKill Task Manager
WinMaximize User 1 - Anki
}
Else
{
WinKill Task Manager
IfWinExist User 1 - Anki
{
WinActivate User 1 - Anki
MouseMove,1298, 981
}
}
}
return
!F4::
MouseMove 350,350
return
Meh:
MsgBox WELL DONE U R NOW FREE
SetTimer,,OFF
a:=10
Return
Lwin::
Return
Rwin::
Return
This script disables alt + f4, kills taskmanager, maximizes the anki window whenver it is minimized and prevents the mouse coming near the red exit button on the outside of the programs window for a user-defined number of minutes. As anki can be navigated without using the mouse, this selectively impedes procrastinating actions without impeding studying.
The script works pretty well, but it can be overcome by restarting the computer or doing a slow logout via control alt delete (win + L doesn't terminate script). Control alt delete is very hard to disable on modern windows builds, likely as a malware prevention safeguard.
My proposed solution is to have the script perform some annoying action (e.g. deleting all desktop shortcuts) when activated, and to undo that same action when the user-defined time period terminates. I believe this would leave the annoying action unfixed if the user logs out/shuts down/restarts/slow log offs.
I've considered using the script to create another annoying script in the startup folder, but this can be circumvented by just logging out rather than restarting/shutting down.
Renaming/deleting keyboard shortcuts is only annoying if the user has a lot of keyboard shortcuts.
Creating a ton of text files on the desktop and other folders is too easy to reverse and can just be ignored by the user until they have finished procreastinating
Disabling the internet would be good, but it would still leave offline distractions (e.g. video games) available.
How best to go about designing such an action that will temporarilly disable a PC that is trivial and reliable, but timeconsuming and boring to undo?
While your AutoHotkey solution is a clever way to dissuade people from exiting out of the program, you will never get a true 100% rock solid solution for the following reason: you are logging in with a user that is allowed to do stuff. If you can do stuff, you and others will figure out a clever way around to do it, and no, as amazing as AutoHotkey is, it can't disable the unplugging of a power cord.
On the other hand, yes, you can make the penalties for circumventing the protections increasingly painful (up to the penultimate format c: nuclear option, which I would garner guarantees 99% compliance), but you will always start to run into issues, and still you won't get compliance.
The better solution is to use features that are baked into Windows via Group/Local Security Policies that will limit things. By using a special user with locked down privileges, they physically won't be able to do things because they can't (for ex. you can disable the start menu, power options, sites, etc.).
You really want to lock things down to a single app? Well Windows has a special Kiosk Mode where you literally can -only- have one app running, and you can't get out of it no matter what. There are dozens of special Kiosk Policies that can be applied from removing sign out options from Ctrl-Alt-Delete to Removing Task Manager.

Fetch the current track info from Spotify app after March 2015 update

I want to pull out the current track information from Spotify windows client using autohotkey.
Although this question Hotkey for next song in Spotify solved some of the problems (the media playback issues) in the commonly used ahk script (can be found in this question: Newest Spotify update: Autohotkeys script broke and below), the track info shortcut still does not work.
^Down::
{
DetectHiddenWindows, On
SetTitleMatchMode 2
WinGetTitle, now_playing, ahk_class SpotifyMainWindow
;StringTrimLeft, playing, now_playing, 10
DetectHiddenWindows, Off
clipboard = %playing%`r`n
return
}
This will give me "Spotify free" no matter what song I am playing.
The main problem is that the tray icon and the task bar icon stopped showing the currently played song information after this update. Only text Windows spy can find from the task bar icon is now "Spotify Free".
So, I tried to get all controllist and extract texts in each of them by following the example in this question: How to obtain textual contents from a window
But, I could only find two controls ("Chrome_WidgetWin_01" and "Chrome_RenderWidgetHostHWND1") and Window spy can find text "Chrome Legacy Window" and this is all it finds.
Is there a way to dig into this further? I noticed in the Windows Task Manager there are 3 spotify.exe instances. Would looking into other processes help?
PS
AHK Window Info 1.7 (http://www.autohotkey.com/board/topic/8204-ahk-window-info-17/) is not available for download at moment. so i could only use Ahk Window Spy 1.3.3 by Decarlo.
Oh, I found the code for AHK Window Info pasted as spoiler at http://www.autohotkey.com/board/topic/8204-ahk-window-info-17/page-6
But it did not help. information found was not more than Ahk Window Spy.
(edit)
UISpy from microsoft gives me a bit more info but it's not possible to get texts in Spotify client. And, I realized that it's a good thing in terms of security (otherwise malware can read my email password etc). So, unless Spotify client wants to expose this information, it would be hard or not possible to do this by ahk. Is this correct or any cleaver way around in this particular case?
EDIT: This solution is no longer needed. The song artist and title have been added back to the Window Title.
The best solution is to downgrade Spotify to a 0.9 version from FileHorse. Then do the following:
Go to C:\Users\YOURUSERNAME\Appdata\Roaming\Spotify
Make a new empy text file
Name it Spotify_new.exe
Right click the file and make the file read-only
Copy this file and name the new one Spotify_new.exe.sig
Spotify needs to delete these files to do an automatic upgrade. The read-only flag on both of these files will prevent upgrading from happening.
I haven't had any issues running an old version at this point in time.

How to debug the next JavaScript event in Chrome, with scripts running in background?

In Chrome DevTools, I want to be able to hit F8 (pause script execution), and then interact with the page's elements to see what script it fires. The goal is to pause script execution as soon as I click on a button, for example.
However, when hitting F8, I'm brought to a certain script file in the Sources tab. It seems to be constantly running, perhaps on a timer. I hit Shift+F11 to step out of the function, but this brings me to the "unpuased" state again in Chrome.
In this case, the script running in the background is Plupload jQuery plugin.
Can I deactive or ignore those scripts running constantly in the backgound, in order to be able to debug page interaction events?
You can use the DOM, XHR, and Event Listener breakpoints menus on the Sources tab to target the operations you would like to investigate. This approach will probably take some experimentation and practice, but it may give you the control you seek.

Scheduled task to run .aspx page stuck on running

Hey I have a scheduled task going which basically laucnhes a .aspx page with IE Explorer, i know theres better ways of doing this i.e console apps etc but im stuck with this for the moment.
So the scheduled task runs fine and launches the ie and the page and the script on the onload on that page runs fine to. But the IE window stays open and the tasks remains as "Running". Preventing it from running the next time its due to run.
How can I get the scheduled tasks to stop "running" and maybe even close that IE windows cheers!
If you're looking to just make a HTTP request to the page, instead of opening a browser window, (get Firefox, okay?), you could launch curl http://server/path/to/script.aspx which is a command-line app, which makes the request and then quits immediately after.
For this, you'll need to download curl from http://curl.haxx.se/latest.cgi?curl=win32-ssl

Strange behavior by the BDE Administrator

Logged into my Windows XP SP2 computer using my normal user account (which has Local Admin privileges), when I start the BDE Administrator -- either from the Control Panel or from the BDEADMIN.EXE directly -- I never get the GUI. It shows up on my task bar, and shows up in the Task Manager, but the GUI never appears. I can close the program by right-clicking on the task bar and choosing close. (note that "never" means not within 5 minutes of launching the program)
If I log into the same exact computer using a different user account (which also has Local Admin privileges), when I start the BDE Administrator, it loads the GUI within a couple seconds.
I used to be able to use the BDE Administrator while logged in under my normal user account, so it's not like this has always been a problem.
While this issue may not be directly programming related, it does make developing and testing a pain when I have to log off and back on a couple of times just to make changes to my BDE configuration.
I am totally stumped. Any idea what might be causing this odd behavior?
One idea is that you may have had two screens running on this box and dragged the window off screen.
Just search for the registry keys that control where the window opens up and delete them. Alternatively, you should be able to right click on the program in the task bar and select Move. Then use your arrow keys to bring it back.
Regardless, I'm voting to close.