CMD TaskKill Explorer.exe减慢打开文件资源管理器

时间:2017-09-08 17:47:22

标签: windows cmd windows-8.1 windows-explorer taskkill

我正在运行Windows 8.1,并且在使用CMD重新启动Explore.exe时出现问题。代码工作有关杀死explorer.exe并重新启动它,但一旦这两个代码运行,我根本无法使用Windows资源管理器。要解决此问题,我必须通过右键单击并选择重新启动来重启任务管理器中的Explorer.exe。我也可以结束这个过程并开始执行新的任务'并输入explorer.exe。如果我不能打开任何文件夹,复制或移动任何文件。我可以修改我的脚本,打开Firefox,然后打开chrome。 Excel以相同的速度运行我的宏。

为什么在运行这两个代码(任何一个)之后,文件浏览器会很慢打开并运行?

我的代码:

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

如果我运行此代码,则会出现同样的问题

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

Taskkill /F /IM EXPLORER.EXE >nul

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

START EXPLORER.EXE >NUL

PS我有一个注册表单独的过程,以便在EXPLORER.EXE壳和文件探索者之间区分

1 个答案:

答案 0 :(得分: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
    )
)