Last active
December 17, 2015 05:48
-
-
Save stuartwakefield/5560133 to your computer and use it in GitHub Desktop.
Batch script for updating my context menu "New" items
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Windows Registry Editor Version 5.00 | |
[HKEY_CLASSES_ROOT\.conf] | |
@="NotePadPP.conf" | |
[HKEY_CLASSES_ROOT\.conf\ShellNew] | |
"NullFile"="" | |
[HKEY_CLASSES_ROOT\NotePadPP.conf] | |
@="Configuration File" | |
[HKEY_CLASSES_ROOT\NotePadPP.conf\shell\open\command] | |
@="\"C:\\Program Files (x86)\\Notepad++\\notepad++.exe\" \"%1\"" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Windows Registry Editor Version 5.00 | |
[HKEY_CLASSES_ROOT\.generic] | |
@="GenericFile" | |
[HKEY_CLASSES_ROOT\.generic\ShellNew] | |
"NullFile"="" | |
[HKEY_CLASSES_ROOT\.generic\ShellNew\Config] | |
"NoExtension"="" | |
[HKEY_CLASSES_ROOT\GenericFile] | |
@="Generic File" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Windows Registry Editor Version 5.00 | |
[HKEY_CLASSES_ROOT\.php] | |
@="PHPFile" | |
[HKEY_CLASSES_ROOT\.php\ShellNew] | |
"NullFile"="" | |
[HKEY_CLASSES_ROOT\PHPFile] | |
@="PHP Script" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
set DIRPATH=%~dp0 | |
set LOGFILE=regup.log | |
call :log "Removing unused items from new menu" | |
call :run-regedit-file RemoveUnusedShellNew | |
:: Check that the keys have been deleted | |
call :assert-deleted-shell-new-reg .jnt\jntfile "Journal File" | |
if not %ERRORLEVEL%==0 goto :error | |
call :assert-deleted-shell-new-reg .txt "Text Document" | |
if not %ERRORLEVEL%==0 goto :error | |
call :assert-deleted-shell-new-reg .rtf "Rich Text Document" | |
if not %ERRORLEVEL%==0 goto :error | |
call :assert-deleted-shell-new-reg .zip\CompressedFolder "Compressed (zipped) Folder" | |
if not %ERRORLEVEL%==0 goto :error | |
call :log "Adding Generic File to new menu" | |
call :run-regedit-file AddGenericShellNew | |
call :assert-reg-default HKEY_CLASSES_ROOT\.generic | |
if not %ERRORLEVEL%==0 goto :error | |
call :assert-reg-value HKEY_CLASSES_ROOT\.generic\ShellNew NullFile | |
if not %ERRORLEVEL%==0 goto :error | |
call :assert-reg-value HKEY_CLASSES_ROOT\.generic\ShellNew\Config NoExtension | |
if not %ERRORLEVEL%==0 goto :error | |
call :assert-reg-default HKEY_CLASSES_ROOT\GenericFile | |
if not %ERRORLEVEL%==0 goto :error | |
call :log "Adding Configuration File to new menu" | |
call :run-regedit-file AddConfShellNew | |
call :assert-reg-default HKEY_CLASSES_ROOT\.conf | |
if not %ERRORLEVEL%==0 goto :error | |
call :assert-reg-value HKEY_CLASSES_ROOT\.conf\ShellNew NullFile | |
if not %ERRORLEVEL%==0 goto :error | |
call :assert-reg-default HKEY_CLASSES_ROOT\NotePadPP.conf | |
if not %ERRORLEVEL%==0 goto :error | |
call :assert-reg-default HKEY_CLASSES_ROOT\NotePadPP.conf\shell\open\command | |
if not %ERRORLEVEL%==0 goto :error | |
call :log "Adding PHP Script to new menu" | |
call :run-regedit-file AddPHPShellNew | |
call :assert-reg-default HKEY_CLASSES_ROOT\.php | |
if not %ERRORLEVEL%==0 goto :error | |
call :assert-reg-value HKEY_CLASSES_ROOT\.php\ShellNew NullFile | |
if not %ERRORLEVEL%==0 goto :error | |
call :assert-reg-default HKEY_CLASSES_ROOT\PHPFile | |
if not %ERRORLEVEL%==0 goto :error | |
pause | |
exit /b 0 | |
:run-regedit-file | |
call regedit /S %DIRPATH%%1.reg | |
exit /b %ERRORLEVEL% | |
:assert | |
if not "%1"=="%2" ( | |
call :log %3 ERROR | |
exit /b 1 | |
) | |
call :log %4 | |
exit /b 0 | |
:assert-not | |
if "%1"=="%2" ( | |
call :log %3 ERROR | |
exit /b 1 | |
) | |
call :log %4 | |
exit /b 0 | |
:assert-deleted-shell-new-reg | |
set NAME=%2 | |
set NAME=%NAME:"=% | |
set FAILDELETEDSHELLNEWREG="%NAME% was not removed from new menu" | |
set OKDELETEDSHELLNEWREG="Successfully removed %NAME% from new menu" | |
call :log "Checking %NAME% was removed from new menu" | |
call :assert-deleted-reg HKEY_CLASSES_ROOT\%1\ShellNew | |
call :assert %ERRORLEVEL% 0 %FAILDELETEDSHELLNEWREG% %OKDELETEDSHELLNEWREG% | |
exit /b %ERRORLEVEL% | |
:assert-deleted-reg | |
set FAILDELETEDREG="Key %1 was not deleted!" | |
set OKDELETEDREG="Key %1 was deleted successfully" | |
call :log "Checking key %1 was deleted" | |
call reg query %1 > nul 2>&1 | |
call :assert-not %ERRORLEVEL% 0 %FAILDELETEDREG% %OKDELETEDREG% | |
exit /b %ERRORLEVEL% | |
:assert-reg | |
set FAILREG="Key %1 does not exist!" | |
set OKREG="Key %1 was added successfully" | |
call :log "Checking key %1 exists" | |
call reg query %1 > nul 2>&1 | |
call :assert %ERRORLEVEL% 0 %FAILREG% %OKREG% | |
exit /b %ERRORLEVEL% | |
:assert-reg-value | |
set FAILREGVALUE="Key %1 value %2 does not exist!" | |
set OKREGVALUE="Key %1 value %2 was added successfully" | |
call :log "Checking key %1 value %2 exists" | |
call reg query %1 /v %2 > nul 2>&1 | |
call :assert %ERRORLEVEL% 0 %FAILREGVALUE% %OKREGVALUE% | |
exit /b %ERRORLEVEL% | |
:assert-reg-default | |
set FAILREGDEFAULT="Key %1 default value does not exist!" | |
set OKREGDEFAULT="Key %1 default value was added successfully" | |
call :log "Checking key %1 default value exists" | |
call reg query %1 /ve > nul 2>&1 | |
call :assert %ERRORLEVEL% 0 %FAILREGDEFAULT% %OKREGDEFAULT% | |
exit /b %ERRORLEVEL% | |
:log | |
set LOGTYPE=OK | |
if not "%2"=="" ( | |
set LOGTYPE=%2 | |
) | |
echo %LOGTYPE% ^> %DATE% - %TIME% : %1 >> %DIRPATH%%LOGFILE% | |
exit /b 0 | |
:error | |
echo There was an error, please see the log file for details | |
pause | |
exit /b 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Windows Registry Editor Version 5.00 | |
[-HKEY_CLASSES_ROOT\.jnt\jntfile\ShellNew] | |
[-HKEY_CLASSES_ROOT\.txt\ShellNew] | |
[-HKEY_CLASSES_ROOT\.rtf\ShellNew] | |
[-HKEY_CLASSES_ROOT\.zip\CompressedFolder\ShellNew] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment