Kill a process when user presses “logoff”, “shutdown” or “restart”

0

I often use notepad.exe for temporary messages. I never use it for something I need to save: I have normal text editors and MS OneNote for that.

When I shut down, multiple instances of Notepad is asking to save. What's worse, because of the Windows bug, when I press “no don’t save”, the notepad application stays alive, so I have to close it manually, and once again press “no don’t save”.

I’ve been fighting this problem for years. About 2 years ago, I’ve asked one of the software developers in my team to hack notepad.exe so it doesn’t asks for saving. Unfortunately, I had to reinstall my Windows recently, and I no longer work with that brilliant guy.

Then I’ve tried to use group policy with taskkill /f /im notepad.exe logoff script, only to find out the logoff script is executed after all application are terminated.

I don’t want to install third-party notepad replacements.

I don’t want to disable shutdown prevention at all by tweaking registry. I want the apps like word and excel to be able to prevent shutdown. The problem is only with notepad.

Any ideas? Thanks in advance.

Soonts

Posted 2012-09-13T05:38:49.553

Reputation: 576

1I can't say I've run into the "Windows bug" to which you refer. – None – 2012-09-13T05:50:24.003

1Amusingly I use that specifically to keep windows from shutting down when I don't want it to. – Journeyman Geek – 2012-09-13T06:00:48.907

@RandolphWest, steps to reproduce: 1. Open notepad, type something. 2. Press Windows, Logoff. Wait for the screen to dim, saying "1 program still need to close". 3. Press Cancel on that screen. 4. You'll see a notepad asking "do you want to save changes?" with buttons "Save, Don't Save, Cancel". Press "Don't Save". Expected result: notepad should quit without saving. Actual result: notepad stays running. After that "1 program still need to close" screen, "Don't Save" and "Cancel" buttons are equivalent - WTF? – Soonts – 2012-09-13T09:28:58.813

It turns out I've been using Notepad2 for so many years, I've not run into this on Vista or Windows 7 :-) – None – 2012-09-13T17:27:42.440

Answers

1

How about removing Shutdown and Restart from the Start Menu, disabling the Switch User, Log off and Lock options as well, then creating your own batch files for these actions that will first taskkill notepad and then perform the action (shutdown etc.) required using shutdown.exe or rundll32? You can pin the batch file shortcuts to the taskbar or Start Menu, and even assign keyboard shortcuts to them.

Karan

Posted 2012-09-13T05:38:49.553

Reputation: 51 857