@ECHO OFF :: Check DOS/Windows version IF NOT "%OS%"=="Windows_NT" GOTO Syntax :: Localize variables SETLOCAL :: Check command line arguments IF NOT "%~1"=="" IF /I NOT "%~1"=="/D" IF /I NOT "%~1"=="/Y" GOTO Syntax :: Check if debug mode is requested IF /I NOT "%Debug%"=="ECHO" SET Debug= ECHO.%* | FIND /I "/D" >NUL && SET Debug=ECHO :: Check if confirmation is required SET Confirmed=N ECHO.%* | FIND /I "/Y" >NUL && SET Confirmed=Y :: Check if DEVCON.EXE is available and if not, prompt for download SET DevconAvailable= SET Download= DEVCON.EXE /? >NUL 2>&1 IF ERRORLEVEL 1 ( SET DevconAvailable=No ECHO This batch file requires Microsoft's DEVCON untility. SET /P Download=Do you want to download it now? [y/N] ) :: Start download if requested IF /I "%Download%"=="Y" ( START "DevCon" "http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q311272" ECHO. ECHO Install the downloaded file and make sure DEVCON.EXE is in the PATH. ECHO Then try again. ) :: Abort if DEVCON.EXE is not available yet IF "%DevconAvailable%"=="No" GOTO End :: Ask for confirmation, unless overruled by command line switch IF NOT "%Confirmed%"=="Y" ( ECHO You are about to remove all inactive PnP devices from this computer. SET /P Confirmed=Are you sure you want to continue? [yN] ) IF /I NOT "%Confirmed%"=="Y" GOTO Syntax :: Save a list of all active devices in a temporary file DEVCON Find * | FIND /I /V "matching device(s)" > "%Temp%\DevconFind.txt" IF NOT EXIST "%Temp%\DevconFind.txt" GOTO Syntax :: List all devices, both hidden/inactive and active ones, and remove :: all devices that are not listed as active in the temporary file FOR /F "tokens=1 delims=: " %%A IN ('DEVCON FindAll * ^| FIND /I /V "matching device(s)"') DO ( TYPE "%Temp%\DevconFind.txt" | FIND "%%~A" >NUL IF ERRORLEVEL 1 %Debug% DEVCON Remove "@%%~A" ) :: Remove the temporary file DEL "%Temp%\DevconFind.txt" :: Done ENDLOCAL GOTO:EOF :Syntax ECHO. ECHO RmHidDev.bat, Version 1.00 for Windows 2000 / XP ECHO Use DEVCON to remove all hidden/inactive PnP devices. ECHO. ECHO Usage: RMHIDDEV [ /D ] [ /Y ] ECHO. ECHO Where: /D Will only ECHO the removal commands instead of executing them ECHO /Y Will remove devices without confirmation ECHO. ECHO Notes: [1] This batch file requires Microsoft's DEVCON.EXE, available at ECHO http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q311272 ECHO You will be prompted for download if it isn't found. ECHO [2] This batch file was developed with "ghost devices" on Ghost images ECHO in mind. It has been tested on Windows XP Ghost images only. 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 a recent full backup available in case something might go wrong. ECHO And remember to test, test, test and test before using it in a ECHO production environment. ECHO. ECHO Written by Rob van der Woude ECHO http://www.robvanderwoude.com IF "%OS%"=="Windows_NT" ENDLOCAL