(view source code of rmhiddev.bat as plain text)
:: Check DOS/Windows version
:: Localize variables
:: Check command line arguments
:: Check if debug mode is requested
:: Check if confirmation is required
:: Check if DEVCON.EXE is available and if not, prompt for download
DEVCON.EXE /? >NUL 2>&1
IF ERRORLEVEL 1 (
ECHO This batch file requires Microsoft's DEVCON untility.
:: Start download if requested
IF /I "%Download%"=="Y" (
START "DevCon" "http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q311272"
ECHO Then try again.
:: Abort if DEVCON.EXE is not available yet
:: Ask for confirmation, unless overruled by command line switch
ECHO You are about to remove all inactive PnP devices from this computer.
SET /P Confirmed=Are you sure you want to continue? [yN]
:: Save a list of all active devices in a temporary file
DEVCON Find * | FIND /I /V "matching device(s)" > "%Temp%\DevconFind.txt"
:: List all devices, both hidden/inactive and active ones, and remove
:: all devices that are not listed as active in the temporary file
TYPE "%Temp%\DevconFind.txt" | FIND "%%~A" >NUL
IF ERRORLEVEL 1 %Debug% DEVCON Remove "@%%~A"
:: Remove the temporary file
ECHO Use DEVCON to remove all hidden/inactive PnP devices.
ECHO Usage: RMHIDDEV [ /D ] [ /Y ]
ECHO /Y Will remove devices without confirmation
ECHO Notes:  This batch file requires Microsoft's DEVCON.EXE, available at
ECHO  This batch file was developed with "ghost devices" on Ghost images
ECHO I cannot guarantee flawless operation on any other PC.
ECHO Use this batch file entirely at your own risk. Make sure you have
ECHO production environment.
ECHO Written by Rob van der Woude
|page last uploaded: 2018-12-04, 10:47|