0

I found a simple batch script for restarting explorer in Windows.

@ECHO OFF
echo.
echo Step1: Closing Explorer . . .
echo.
TASKKILL /F /IM explorer.exe
echo.
echo.
echo Step2: Launching Explorer . . .
start explorer.exe
echo.
echo Success: Explorer started.
echo.
echo.
PAUSE

But I would like it to start with a simple, default Windows popup window, something like this:

Do you really want to restart the explorer?
          |Yes|             |NO|

Yes = *.bat file start

No = termination

What will be the easiest way to achieve this?

EDIT:

Why I want the warning message popup? Because I've pinned the script to the taskbar and I prefer the default window popup before launching the script than answering questions in cmd. It's just esthetic's. Can anyone help?

SOLUTION

Set WshShell = CreateObject("WScript.Shell")
A = WshShell.Popup("Do you want to restart the Explorer?", 60, "Windows Explorer Restart Script", 4)
If A = 6 then
Wshshell.Run "C:\path\to\your\Batch_File.bat", 0
WScript.Quit 2
ElseIf A = 7 then
WScript.Quit 1
End If

Result: How it looks like

DanyGee
  • 93
  • 1
  • 7
  • 1
    You're not going to get a Windows messagebox from a batch file, but you don't need it. You can easily get a Y/N answer from the user before executing the batch and exit if they say no. Search here for *[batch-file] get user input* and pick any one of the many results from previous questions. (Although I have no idea why you would ever need this in a batch file. I code on WIndows all day long every day, and support 50 users who work on it as well, and I've needed to force-restart Explorer a total of about two times in the past year.) – Ken White Dec 23 '16 at 22:57
  • There is no need for `start` in your command to restart explorer. `START` is used for starting programs in unusual ways. See http://stackoverflow.com/questions/41030190/command-to-run-a-bat-file/41049135#41049135. Also see for ONE way of doing a popup dialog. http://stackoverflow.com/questions/41230493/batch-file-showing-pop-up-with-timeout-action/41232389#41232389 –  Dec 23 '16 at 23:07

0 Answers0