bread image

Blog Post

shut down a computer on click bat file

: Admin

: 2024-02-27

shut down a computer on click bat file

Creating a script to shut down a computer when a specific folder is clicked involves a combination of batch scripting and Windows shell configuration. Here`s how you can achieve this

Create a Batch Script

First, create a batch script that shuts down the computer. Open Notepad or any text editor and paste the following code:

 @echo off shutdown /s /t 0 /f

Save this file with a  `.bat` extension, such as `shutdown_computer.bat`.

Hide the Batch Script

Next, you'll want to hide the batch script and make it look like a folder. You can achieve this by changing its icon and making it a hidden system file.

  1. Right-click on the batch script file `(shutdown_computer.bat)` and select "Properties."
  2. In the "Properties" window, go to the "Customize" tab.
  3. Click on the "Change Icon..." button and select an icon that resembles a folder.
  4. Click "OK" to apply the changes.
  5. Back in the "Properties" window, check the "Hidden" checkbox under "Attributes."
  6. Optionally, you can also check the "Read-only" checkbox to prevent accidental modifications.

Configure Folder Click Action 

Now, you'll configure the folder to execute the batch script when clicked. You can achieve this using the Windows Registry Editor.

  1. Press Win + R to open the "Run" dialog box.
  2. Type regedit and press Enter to open the Registry Editor.
  3. Navigate to the following key:
HKEY_CLASSES_ROOTDirectoryshell 
  1. Right-click on the "shell" key, select "New," and then "Key." Name the new key whatever you want the folder action to be called (e.g., "Shutdown Computer").
  2. Right-click on the new key you created, select "New," and then "Key." Name this new key "command."
  3. Double-click on the "(Default)" value in the right pane and set its value data to the path of the batch script you created earlier (e.g., "C:path oshutdown_computer.bat").
  4. Close the Registry Editor.

Step 4: Test the Configuration

Now, when you click on the folder with the configured action, the batch script will execute, shutting down the computer.

Important Note:

  • This action will shut down the computer immediately without warning. Make sure to use it responsibly and avoid accidental clicks.
  • Editing the Windows Registry can cause system instability if done incorrectly. Proceed with caution and consider backing up your registry before making changes.
  • Ensure that the batch script (shutdown_computer.bat) is saved in a secure location where it won't be accidentally clicked. 

Recent Blog