-1

I'm Running Windows 8.1 and am having issues restarting Explore.exe with CMD. The code work in regards to killing explorer.exe and starting it up again,but once these 2 codes run I can't use windows explorer at all. To fix this issues I have to restart Explorer.exe in Task Manager by right clicking and selecting restart. I can also end the process and go up to 'run new task' and entering explorer.exe. If I don't I can't open any folder,copy, or move any files. I can modify my script, open Firefox, and open chrome. Excel runs my macro's at the same speed.

Why does after running these 2 codes (either one) make file explorer slow to open and operate in?


My Code:

REM ---------------------
REM TaskKill EXPLORER.EXE
REM ---------------------

FOR /F "tokens=1,2" %%A IN (
    'TaskList /FI "IMAGENAME eq EXPLORER.EXE"'
) DO (
    IF /I "%%A" == "EXPLORER.EXE" (
        TaskKill /F /IM %%A >nul
    )
)

REM ------------------
REM START EXPLORER.EXE
REM ------------------

START EXPLORER.EXE >NUL

The Same problem happens if I run this code


REM ---------------------
REM TaskKill EXPLORER.EXE
REM ---------------------

Taskkill /F /IM EXPLORER.EXE >nul

REM ------------------
REM START EXPLORER.EXE
REM ------------------

START EXPLORER.EXE >NUL

PS I HAVE THE REGISTRY SEPARATE PROCESS AS 1 TO DISTINGUISH BETWEEN EXPLORER.EXE THE SHELL AND THE FILE EXPLORER

Brett Nelson
  • 113
  • 3
  • 19
  • There's no problem statement nor question asked here. – Sam Axe Sep 08 '17 at 17:51
  • Why are you killing Explorer.exe at all? – Ken White Sep 08 '17 at 17:55
  • I have a weekly maintenance I run 3 programs. One of these programs opens windows explorer when it finishes as a glitch. so I run the code it opens the program when it finishes I see there are 2 explorer.exe running so I end the new one and continue on with the other programs. – Brett Nelson Sep 08 '17 at 17:57
  • 1
    So instead of fighting with Explorer, fix the *glitch*. It's better to fix a problem in your code than to futz around with the OS. – Ken White Sep 08 '17 at 18:05
  • If I could I would. The glitch isn't part of a program I've created. It's TFC.exe by old timer. – Brett Nelson Sep 08 '17 at 18:06

1 Answers1

0
SET /A RunningCount=0

rem ----------------------------------------------------------
rem FIGURE OUT HOW MANY WIN EXPLORER.EXE'S THAT ARE RUNNING
rem ----------------------------------------------------------
FOR /F "tokens=1,2,5,6" %%A IN (
    'TASKLIST /FI "IMAGENAME eq EXPLORER.EXE"'
) DO (
    IF /I "%%A" == "EXPLORER.EXE" (
        SET /A RunningCount=!RunningCount!+1
        SET "WinExplorerMemory!RunningCount!=%%C"
        SET "WinExplorerPID!RunningCount!=%%B"
    )
)

rem ----------------------------------------------------------
rem THIS REMOVES THE COMMA'S IN THE STRING
rem ----------------------------------------------------------
IF "%WinExplorerMemory1%" NEQ "" SET WinExplorerMemory1=%WinExplorerMemory1:,=%
IF "%WinExplorerMemory2%" NEQ "" SET WinExplorerMemory2=%WinExplorerMemory2:,=%

rem ----------------------------------------------------------
rem FIGURES OUT WHICH PID IS USING THE MOST MEMORY
rem ----------------------------------------------------------
IF "%RunningCount%" EQU "1" (
    SET WinExplorerShellPID=%WinExplorerPID1%
) ELSE (
    IF [%WinExplorerMemory1%] GTR [%WinExplorerMemory2%] (
        SET WinExplorerShellPID=%WinExplorerPID1%
        TASKKILL /F /PID %WinExplorerPID2% >NUL
    )
    IF [%WinExplorerMemory2%] GTR [%WinExplorerMemory1%] (
        SET WinExplorerShellPID=%WinExplorerPID2%
        TASKKILL /F /PID %WinExplorerPID1% >NUL
    )
)
Brett Nelson
  • 113
  • 3
  • 19