A simple Windows batch tool to load and unload a kernel-mode driver using the Service Control Manager (SCM). The script elevates itself to administrator, creates a kernel service on demand, starts/stops it, and removes the service when unloading.
- Self-elevates to Administrator when needed.
- Loads a driver by creating a kernel service with
sc createandsc start. - Unloads a driver by
sc stopandsc delete. - Status display for service (loaded/unloaded) and state (running/stopped).
- Separate actions for load, start, stop, unload, and combined flows.
- Uses the script name as the service name and
<scriptname>.sysas the driver file.
- Windows with Administrator privileges.
- Driver file located in the same directory as the script.
- Driver filename must match the script name:
- Script:
driver.bat - Driver:
driver.sys
- Script:
SERVICE_NAMEis set to the batch file name (without extension).DRIVER_FILEis set toSERVICE_NAME + .sys.DRIVER_PATHpoints to the.sysfile in the same folder.
- Copy your driver file next to the script and rename it to match the script name:
driver.batdriver.sys
- Run the script:
- Double-click it, or run from an elevated terminal.
- Choose an option:
1to load and start2to stop and unload3to start4to stop5to load6to unload0to exit
- If a start fails, the script rechecks the service state to avoid false errors.
- If a load fails after service creation, the script deletes the service to avoid leftovers.
- The driver is started on demand (
start= demand). - Some drivers may require testsigning or proper signing depending on your Windows configuration.
- Driver file not found: Ensure the
.sysfile is in the same directory and matches the script name. - Failed to create/start service: Run as Administrator and verify the driver is compatible with your OS version.
- Service already loaded: Unload first, or choose the unload option to remove it.