How to immunise my antiprocrastination script against logout and shutdown? - autohotkey

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.

Related

Disable ALL default shortcuts in Visual Studio Code

Is there an easy way to disable all default shortcuts in Visual Studio Code?
From the UI, you can delete shortcuts one at a time, but due to the sheer volume of shortcuts, this would take quite some time.
Thanks
Edit 1 - When you hold delete, it continuously adds the same disable to keybindings.json. I'm guessing the fact that it updates a physical file as you interact with the UI, it requires slower user interactions.
keybindings.json after holding delete:
#ArtemBondar unfortunately you can't just hold the Delete button, at least not on the machines I've tested. At most I could delete 1 roughly every second. Any faster and it wouldn't register the delete calls. –
On my Windows 10 machine it's working at about 2-3 deletes/second speed.
Really don't know why you need to disable all shortcuts, just grab this keybindings.json.
Edit 1 - When you hold delete, it continuously adds the same disable to keybindings.json. I'm guessing the fact that it updates a physical file as you interact with the UI, it requires slower user interactions.
It seems like to be a good reason to create a new issue at VS Codes GitHub.
Meanwhile, I've also found another one while making that keybindings.json.

Suggestions for a bad PowerShell Script

We have a legacy server service running on a Windows 7 desktop that keeps crashing with a popup window reporting a memory error. The popup stops all processing on the machine. Once the "OK" button is clicked on the popup the system recovers and moves on. The root problem appears to be inside a compiled DLL that the application uses.
This popup usually happens between 9pm and 11pm every couple days.
It happens when no one is signed into the PC, so the popup displays in front of the CTRL+ALT+Delete message for signing in.
I can click OK and it continues processing, signing into the computer.
CHALLENGE:
This is a legacy application that will be replaced when budget allows (maybe next Summer) so there is no budget for upgrade or paying a consultant to fix the root problem.
All we need to do is click the OK button when the "Application Popup" event is thrown (logged in the Event Manager)
I know that it would be WRONG to write a script to satisfy the popup. Fixing the root cause is the CORRECT action.. but we have no support to spend money at this time. And since it's a compiled DLL, we can't fix the code.
Is there a PowerShell script that could:
Watch for a specific event "Application Popup" and if it occurs simulate pressing the ENTER key?
Run in the background, signed out of a user account.
If PowerShell isn't the answer, is there a better macro or script tool to get us by?
I know it's "bad practice" but we just need to get along until we get some budget dollars.
Powershell probably isn't the best answer in this case. I'd suggest using something like AutoIt (the WinWaitActive function would be useful in your case).
I have used AutoIt in the past and have found it very useful for Windows GUI automation.

Is there a way to automatically log onto a Windows XP machine at specific time?

How to set a specific logon time for a specific user on Windows XP?
For example, the computer is an "always on machine" and most of the time no one is logged on. I want to set a time for my user to log on, without someone actually having to be in front of the machine. I've tried a workaround with the built-in auto logon function (control userpassword2), but I still need a secure system as I'm not the only user, and would still want a password even if I was the only user.
I have searched for third party software, but to no avail. I've a good knowledge of batch and Python scripting and a little of Java, so any pointers with any of those would help.
How can it be "secure" if it logs you on without you being there? Surely it would be better for it to wait for you to type in a password (i.e. the login prompt)?
If you want a fast "startup" time, then you can lock the workstation (ctrl+alt+del to open the Task Manager and then click 'Lock'. This shows a dialog just like the login prompt, but when you enter your password you instantly continue your existing session). Or if you want to be more eco friendly, put your PC into Sleep mode, which most PCs will return from (again with an optional password prompt) in less than 5 seconds.
One way I just thought of: Run a Vnc Server, and hack into an open source viewer program. Then you can rig it with some code to pass keyboard commands back into the computer, maybe implement some screen scraping to make sure it only does it when appropriate.
But seriously, there has to be a better way. Why are you trying to do this?

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.

Automate Dual Monitor Setup In Vista

I use a laptop as my primary workstation. Sometimes I work alone on it, but a significant portion of the time, I'm at my office desk and I hook up an external monitor to increase my workspace.
Every time I perform this action, I click the same dialog boxes in Windows Vista to setup the dual screen and position the window. It seems like a repeatable task that I could automate.
I'd like to be able to plug in my monitor cable, double click a program and have it automatically configure the monitor.
What type of program could do this? I haven't found much online that relates. I'm thinking of trying an autohotkey script, or the Windows Accessibility API with PowerShell. Has this problem already been solved?
Clarification: I'm specifically looking to automate the steps I use with my mouse that invoke the base functionality in Windows Vista.
Right click on desktop
Select Personalize in context menu
Click display settings
Click monitor #2, then click checkbox to "Extend desktop to this monitor"
Click and drag monitor #2 to the left of monitor #1
Click OK to close the dialog
Click Yes in the subsequent pop up to accept these monitor settings
Update: Windows 7 does this automatically
I just upgraded to Windows 7 and it remembered my dual monitor settings. I set them once at work as listed above, then unplugged and worked at home over the weekend. I came in on Monday morning, booted up, plugged in and whammo! It just worked. Thanks Windows 7!
I haven't seen an existing utility that does this but it would be pretty easy to write one using the Win32 APIs. Via this page, EnumDisplayDevices gets a list of display devices, EnumDisplaySettingsEx gets the current settings and ChangeDisplaySettingsEx will make the changes.
The DEVMODE.dmPosition field should contain the virtual coordinates of the top left corner of the display, with the primary monitor always being (0,0) and the others relative to that.
The tool would need two modes, the first saves the current settings to a config file, and the second applies the settings from the config. I'd store/retrieve only the display device index, name, and each of the DEVMODE.dm* fields mentioned in the ChangeDisplaySettingsEx docs. A text-based config allows for hand-edits.
Try UltraMon for excellent dual monitor support. I've been using it for years on a number of different laptops and desktops and it works great. I've only used XP so I am not sure how it works with Vista.
My Leovo T60p does this automatically without any special steps. Try upgrading your video drivers, and check the manufacturer's site for any utilities that can do that.
If you have windows vista or 7 you could hit the windows_key + P. You have a bunch of options to select including extend
I believe Ultramon would in fact work. In the right-click menu on the Ultramon icon in the systray there is a "disable/enable secondary" command.
I think you could simply:
plug in the second monitor
select "enable secondary"
Here I am, three years later, answering my own question! Yay!!!
This is easily scripted with http://www.autohotkey.com
Here's an example script for swapping between one monitor and two monitors with Windows+1 and Windows+2. AutoHotKey also allows for click and drag behavior that would be needed to swap the position of the second monitor.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn ; Recommended for catching common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#1::
Send {LWin}
WinWaitActive Start menu
Send Adjust Screen Resolution
Send {enter}
WinWaitActive Screen Resolution
ControlClick ComboBox3
Send {PgDn}
Send {Up} ; Select "Show desktop only on 1"
Send {enter}
Sleep 3000 ; workaround - cannot select accept/revert window?
Send {left}
Send {enter} ; accept changes
Return
#2::
Send {LWin}
WinWaitActive Start menu
Send Adjust Screen Resolution
Send {enter}
WinWaitActive Screen Resolution
ControlClick ComboBox3
Send {PgDn}
Send {Up}
Send {Up} ; Select "Extend these displays"
Send {enter}
Sleep 3000 ; workaround - cannot select accept/revert window?
Send {left}
Send {enter} ; accept changes
Return