Windows 7 Script for Disabling Flash/Pen Drive in Win 7

baijuep

New Member
Joined
Sep 19, 2012
Messages
2
i am using win 7 and i want a script to disable the flash/pen drive and enable it when required. when i was using xp there was a script which is not working in win7
 

Solution
To create a script to disable and enable a flash/pen drive on Windows 7, you can use a combination of batch commands and Device Manager actions. Here's a general outline of the steps you can follow to achieve this:
  1. Identify the Device ID of the Flash Drive:
    • You need to find the Device ID of the flash drive you want to disable. This ID will be used in the script to target the specific device.
    []Create a Batch Script to Disable the Flash Drive:
    • Create a batch script that uses the devcon utility (Device Console) to disable the flash drive based on its Device ID.
    • devcon is a command-line utility that acts as an alternative to Device Manager for device management.
    ...
To create a script to disable and enable a flash/pen drive on Windows 7, you can use a combination of batch commands and Device Manager actions. Here's a general outline of the steps you can follow to achieve this:
  1. Identify the Device ID of the Flash Drive:
    • You need to find the Device ID of the flash drive you want to disable. This ID will be used in the script to target the specific device.
    []Create a Batch Script to Disable the Flash Drive:
    • Create a batch script that uses the devcon utility (Device Console) to disable the flash drive based on its Device ID.
    • devcon is a command-line utility that acts as an alternative to Device Manager for device management.
    [
    ]Create a Batch Script to Enable the Flash Drive:
    • Similarly, create a batch script to enable the flash drive when required. This script will use devcon to enable the device using its Device ID.
  2. Run the Scripts as Administrator:
    • To perform these actions, the scripts need to be executed with administrator privileges to make changes to the device. Here is a basic template for the scripts:

      Batch Script to Disable Flash Drive:​

      Code:
      @echo off set DeviceID=ENTER_DEVICE_ID_HERE :: Disable the Device devcon disable %DeviceID% echo Flash Drive Disabled.

      Batch Script to Enable Flash Drive:​

      Code:
      @echo off set DeviceID=ENTER_DEVICE_ID_HERE :: Enable the Device devcon enable %DeviceID% echo Flash Drive Enabled.
      In these scripts:
      • Replace ENTER_DEVICE_ID_HERE with the actual Device ID of your flash drive.
      • You will need to run these scripts in an elevated Command Prompt (Run as Administrator) for them to work properly.
      To find the Device ID of your flash drive, you can use devcon itself or Device Manager. Let me know if you need further assistance on how to find the Device ID or if you encounter any issues while setting this up on Windows 7.
 

Solution
Back
Top