@ECHO OFF :: Check Windows version and command line arguments IF NOT "%OS%"=="Windows_NT" GOTO Syntax IF NOT "%~1"=="" GOTO Syntax :: Allow delayed variable expansion, which we will :: (ab)use for string substitution on percent signs. SETLOCAL ENABLEDELAYEDEXPANSION :: Save the current .VBS file type association in a temporary batch :: file which we can use later to restore the original settings. FOR /F "tokens=1* delims==" %%A IN ('ASSOC .vbs') DO SET VbsAssoc=%%B FOR /F "tokens=1* delims==" %%A IN ('FTYPE %VbsAssoc%') DO SET VbsFType=%%B SET VbsFType=!VbsFType:%%=%%%%! IF NOT EXIST restore_vbs_assoc.bat ( > restore_vbs_assoc.bat ECHO @ECHO OFF >> restore_vbs_assoc.bat ECHO FTYPE %VbsAssoc%=%VbsFType% ) :: Find the location of CSCRIPT.EXE in the current directory or in the PATH variable. :: Simplified code by David Keller. FOR %%A IN (cscript.exe) DO SET CScript=%%~f$PATH:A :: Change the file type association for .VBS to CSCRIPT.EXE. IF DEFINED CScript ( FTYPE %VbsAssoc%=%CScript% //NoLogo "%%1" %%* SET Error=0 ) ELSE ( ECHO CSCRIPT.EXE was not found. ECHO The file type association for .VBS has been left unaltered. SET Error=1 ) :: Done. ENDLOCAL & EXIT /B %Error% :Syntax ECHO. ECHO VBSAssoc.bat, Version 1.10 for Windows NT 4 and later ECHO Associate .VBS files with CSCRIPT.EXE ECHO. ECHO Usage: VBSASSOC.BAT ECHO. ECHO Note: Use "restore_vbs_assoc.bat", created in the current ECHO directory, to restore the original file association. ECHO. ECHO Credits: Code optimized by David Keller. ECHO. ECHO Written by Rob van der Woude ECHO http://www.robvanderwoude.com