开发者

Gently Terminate Explorer.exe

I have done a lot of searching but I have not been able to discover a straightforward way to gently terminate the explorer shell in an XP batch file.

Why would I want to, you ask (since almost every time someone asks this someone else wants to know why)? The answer is simply开发者_开发知识库 this: I run a batch job at the end of the day which saves my toolbar configuration. When the explorer shell terminates normally, it writes the toolbar configuration to a registry key, which can then be exported and restored after I run CCleaner at the beginning of the week. If explorer is terminated with, for example, taskkill, it usually fails to write the registry key and the resulting export file does not always accurately reflect the current configuration of the toolbars.

I have tried using CMDOW "program manager" /cls but this just brings up the "Shut Down Windows" dialog - sometimes it makes the computer shut down even if you hit the "Cancel" button. Since bringing up the "Shut Down Windows" dialog and hitting "Cancel" while holding down "Ctrl, Alt, Shift" will cause explorer to gently die, I have looked at a vbs script using sendkeys but sending "%{F4}" assumes that the desktop is the foremost window. I thought I might try coding some HotKeyP macros - it has the capability of raising the "Shut Down Windows" dialog - but once the "Shut Down Windows" dialog is raised, HotKeyP can't seem to access it.

What message is Explorer receiving so that it knows to terminate gently as opposed to shut the whole computer down - that's what I want to know.


The following command line text will terminate any EXPLORER.EXE process but not shut down the computer.

taskkill /fi "imagename eq EXPLORER.EXE" /f /t

to know more about taskkill use the /? parameter.


I don't think Microsoft provides a way to do what you describe without scripting the Explorer UI. The prescribed way to close explorer and save all settings is to log off.

There are generally three ways to close a program:

  1. TerminateProcess()
    • This causes the kernel to stop scheduling the process threads, and unloads the process from memory. As you rightly point out, this doesn't give explorer a chance to save its settings.
    • This is what "taskkill /f" does.
  2. Send a WM_CLOSE message to the program's main window
    • Programs can decide to handle this however they want. Most will close, but Explorer treats it as a signal to log off, which is not what you want.
  3. Use some program-specific method of asking it to shut down.
    • Explorer.exe does provide this via the GUI (ctrl+shift+rightclick on any non-button part of the start menu), but it does not provide a command-line way to do this.

If you are really set in what you want to do, you can use wscript or another UI scripting library to manipulate the GUI and perform option 3.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜