Showing posts with label restarting. Show all posts
Showing posts with label restarting. Show all posts

Saturday, January 22, 2011

Batch File To Restart Explorer And Reopen Windows

Though this is not a very common task, I suppose this example of batch scripting is still very useful for advanced users of batch files. You can change anything you want in a couple of minutes, especially with help of our powerful and handy batch files editor.
Here is the code to restart Windows Explorer and reopen all windows of the running applications:
@echo off setlocal enabledelayedexpansion for /f "usebackq tokens=8*" %%a in (`"cmdow /t /f | find /i "explorer""`) do ( if /i "%%a"=="explorer" set "open_windows=!open_windows! "%%b"" ) taskkill /f /im explorer.exe>nul start explorer for %%a in (%open_windows%) do ( if /i %%a=="My Computer" (start /min explorer shell:DriveFolder) else ( start /min explorer %%a) )
Hope you'll find this code useful.

Wednesday, January 19, 2011

Detecting the Insertion of USB Flash in Batch Files

How to detect that user inserts USB Flash drive and make computer shut down after this? Here you can see step-by-step explanation.
1. Download and install Dr.Batcher, the program designed to create and edit batch files.
2. Start Dr.Batcher and create new empty batch script (File->New->Empty Batch Script).
3. Add command named "Display a message" (Command->Add), click OK in the "Add Command" dialog.
4. Choose "off" as the first parameter and click "OK".
5. Add command named "Set Label".
6. Set loop as a label name, click "OK".
7. Add command named "If (Condition)". Choose "Edit the condition" in the appeared dialog.
8. Choose "File Exists (Condition Only)". 9. Set the letter of the flash drive as the parameter in the following dialog. Note: "\." after the drive letter should not be removed.
9. Add command named "Go to a Label".
10. Set loop as the label name. Click "OK".
11. Following the instructions in paragraphs 5 and 6, add a label with name end.
12. Add command named "Shut Down or Restart Computer".
13. Set the first parameter of this command equal to -r to restart or -s to shut down
14. To make this file start automatically when you log on, place it inside the "Startup" folder in Start menu.
15. Enjoy!

Translate