Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for dll_menu.bat

(view source code of dll_menu.bat as plain text)

  1. @ECHO OFF
  2.  
  3. ECHO.
  4. ECHO DLL_Menu.bat,  Version 1.01 for Windows 2000 / XP
  5. ECHO Add "Register" and "Unregister" entries to
  6. ECHO Explorer's context menu for .DLL and .OCX files
  7. ECHO.
  8. ECHO Usage:   DLL_MENU
  9. ECHO.
  10. ECHO Warning: This batch file will modify the registry.
  11. ECHO          Testen in Windows XP SP2 only.
  12. ECHO          Use this batch file at your own risk.
  13. ECHO.
  14. ECHO Note:    Before modifying a registry entry, this batch file
  15. ECHO          will export the current settings to a set of .REG
  16. ECHO          files (*_Restore.reg) in the current directory
  17. IF     "%OS%"=="Windows_NT" ECHO          ("%CD%").
  18. IF NOT "%OS%"=="Windows_NT" CD
  19. ECHO          In case of emergency, doubleclick these .REG
  20. ECHO          files to restore the previous configuration.
  21. ECHO.
  22. ECHO Written by Rob van der Woude
  23. ECHO http://www.robvanderwoude.com
  24. ECHO.
  25.  
  26. :: Check Windows version and command line arguments
  27. IF NOT "%OS%"=="Windows_NT" GOTO End
  28. IF NOT  "%~1"==""           GOTO End
  29. VER | FIND " NT" > NUL  &&  GOTO End
  30.  
  31. :: Use local variables
  32. SETLOCAL
  33.  
  34. :: Ask for confirmation
  35. ECHO You are about to modify the registry.
  36. SET /P Answer=Are you sure you want to continue? [y/N] 
  37. IF /I NOT "%Answer:~0,1%"=="Y" GOTO End
  38.  
  39. :: Get or set the file type for DLLs - backup existing settings before changing
  40. FOR /F "tokens=1* delims==" %%A IN ('ASSOC .DLL') DO SET DllFile=%%B
  41. IF NOT DEFINED DllFile (
  42. 	IF NOT EXIST "C:\Dll_Restore.reg" START /WAIT REGEDIT.EXE /E Dll_Restore.reg "HKEY_CLASSES_ROOT\.DLL"
  43. 	ASSOC .DLL=dllfile
  44. 	SET DllFile=dllfile
  45. )
  46.  
  47. :: Get or set the file type for OCXs - backup existing settings before changing
  48. FOR /F "tokens=1* delims==" %%A IN ('ASSOC .OCX') DO SET OcxFile=%%B
  49. IF NOT DEFINED OcxFile (
  50. 	IF NOT EXIST "C:\Ocx_Restore.reg" START /WAIT REGEDIT.EXE /E Ocx_Restore.reg "HKEY_CLASSES_ROOT\.OCX"
  51. 	ASSOC .OCX=ocxfile
  52. 	SET OcxFile=ocxfile
  53. )
  54.  
  55. :: Backup existing settings before changing
  56. IF NOT EXIST "C:\%DllFile%_Restore.reg" START /WAIT REGEDIT.EXE /E "%DllFile%_Restore.reg" "HKEY_CLASSES_ROOT\%DllFile%\shell"
  57. IF NOT EXIST "C:\%OcxFile%_Restore.reg" START /WAIT REGEDIT.EXE /E "%OcxFile%_Restore.reg" "HKEY_CLASSES_ROOT\%OcxFile%\shell"
  58.  
  59. :: Create a temporary REG file
  60. (
  61. 	ECHO Windows Registry Editor Version 5.00
  62. 	ECHO.
  63. 	ECHO [HKEY_CLASSES_ROOT\%DllFile%\shell]
  64. 	ECHO.
  65. 	ECHO [HKEY_CLASSES_ROOT\%DllFile%\shell\Register]
  66. 	ECHO.
  67. 	ECHO [HKEY_CLASSES_ROOT\%DllFile%\shell\Register\command]
  68. 	ECHO @="%windir:\=\\%\\system32\\regsvr32.exe \"%%1\""
  69. 	ECHO.
  70. 	ECHO [HKEY_CLASSES_ROOT\%DllFile%\shell\Unregister]
  71. 	ECHO.
  72. 	ECHO [HKEY_CLASSES_ROOT\%DllFile%\shell\Unregister\command]
  73. 	ECHO @="%windir:\=\\%\\system32\\regsvr32.exe /u \"%%1\""
  74. 	ECHO.
  75. 	ECHO [HKEY_CLASSES_ROOT\%OcxFile%\shell]
  76. 	ECHO.
  77. 	ECHO [HKEY_CLASSES_ROOT\%OcxFile%\shell\Register]
  78. 	ECHO.
  79. 	ECHO [HKEY_CLASSES_ROOT\%OcxFile%\shell\Register\command]
  80. 	ECHO @="%windir:\=\\%\\system32\\regsvr32.exe \"%%1\""
  81. 	ECHO.
  82. 	ECHO [HKEY_CLASSES_ROOT\%OcxFile%\shell\Unregister]
  83. 	ECHO.
  84. 	ECHO [HKEY_CLASSES_ROOT\%OcxFile%\shell\Unregister\command]
  85. 	ECHO @="%windir:\=\\%\\system32\\regsvr32.exe /u \"%%1\""
  86. 	ECHO.
  87. ) > "%Temp%.\~%~n0.reg"
  88.  
  89. :: Import the new settings in the registry
  90. START /WAIT REGEDIT.EXE /S "%Temp%.\~%~n0.reg"
  91.  
  92. :: Delete the temporary REG file
  93. DEL "%Temp%.\~%~n0.reg"
  94.  
  95. ENDLOCAL
  96. :End
  97.  

page last modified: 2024-04-16; loaded in 0.0051 seconds