Automatically close Windows Explorer

I am trying to write a program that closes the explorer and then starts another program.
I have a problem while trying to close explorer using the following code:

foreach (Process p in Process.GetProcesses()) if (p.MainModule.ModuleName.Contains("explorer")) p.Kill(); 

can someone please let me know why he does this and provides a solution
CHEERS

ps is not a malicious program, it will launch a game that does not work properly when the explorer is in the background.

+4
source share
3 answers

The problem is that you can have several versions of Explorer working at any given time ... and you usually need at least one of them. The shell that houses the Start menu is actually an instance of Explorer. Therefore, if you close all instances of Explorer, you will also disable the main shell, which you do not want to do.

However, the fastest way to get all instances of Explorer and kill them:

 foreach (Process p in Process.GetProcessesByName("explorer")) { p.Kill(); } 
+5
source

There is a simple undocumented way to exit the explorer; see also the Exit Explorer (Programmatically) question. It is intended for developers working with shell extensions.

This procedure is different for Windows XP and Windows 7:

Windows XP: Open the shutdown dialog box (Start> Shutdown), then cancel the dialog by pressing CTRL-SHIFT-ALT-ESC (or hold down the CTRL-SHIFT-ALT key and click with the mouse).

Windows 7: Open the Start menu, and then hold CTRL-SHIFT until the right key is in an empty area of ​​the Start menu, see screenshot . A context menu will appear where the second entry is "Exit Explorer" (without CTRL-SHIFT, the context menu has only one entry)

+5
source

postscript is not a malicious program, it launches a game that does not work properly when the explorer is in the background

Explorer is an essential component of Windows. You must debug the cause of the problems while Explorer is running and fix them.

Killing Explorer will cause serious problems for your users.

0
source

Source: https://habr.com/ru/post/1303246/


All Articles