Created
January 11, 2012 11:58
-
-
Save markusrt/1594355 to your computer and use it in GitHub Desktop.
Enables debugging for a specified executable. This causes a debugger [vsjitdebugger.exe] to be launched each time the program starts.
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 | |
setlocal | |
REM Config section, change if required | |
set REG=C:\Windows\System32\reg.exe | |
set DEBUGGER=vsjitdebugger.exe | |
REM Config section end | |
set method=enable | |
set debugExe= | |
set args= | |
set verbose=0 | |
:optStart | |
set ARG=%~1 | |
if "%~1" == "" goto :optEnd | |
if /i "%1" == "/enable" ( | |
set method=enable | |
goto :nextOpt | |
) | |
if /i "%1" == "/disable" ( | |
set method=disable | |
goto :nextOpt | |
) | |
if /i "%ARG:~0,5%" == "/exe:" ( | |
set debugExe=%ARG:~5% | |
goto :nextOpt | |
) | |
if /i "%1" == "/?" ( | |
goto :help | |
) | |
if /i "%1" == "/v" ( | |
set verbose=1 | |
goto :nextOpt | |
) | |
if /i "%ARG:~,1%" == "/" ( | |
echo %~n0: Unknown option %ARG% 1>&2 | |
exit /b 1 | |
) | |
set args=%args% "%~1" | |
:nextOpt | |
shift /1 | |
goto :optStart | |
:optEnd | |
if "%debugExe%" == "" goto :help | |
if "" == "%args%" set args=. | |
call :%method% %args% && ( exit /b 0 ) || ( exit /b 1 ) | |
exit /b 0 | |
:enable | |
if "1" == "%verbose%" echo on | |
%REG% ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\%debugExe%" /v debugger /t REG_SZ /d %DEBUGGER% /f && exit /b 0 | |
@echo off | |
exit /b 1 | |
:disable | |
if "1" == "%verbose%" echo on | |
%REG% DELETE "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\%debugExe%" /f && exit /b 0 | |
@echo off | |
exit /b 1 | |
:help | |
echo Enables debugging for a specified executable. This causes a debugger [%DEBUGGER%] to be launched each time the program starts. | |
echo. | |
echo USAGE: %~n0 /enable /exe:executable [/v] | |
echo %~n0 /diable /exe:executable [/v] | |
echo. | |
echo /enable Enables debugging for the specified executable | |
echo /disable Disables debugging for the specified executable | |
echo /v "Verbose" output | |
echo. | |
echo EXAMPLE: %~n0 /enable /exe:cmd.exe | |
echo. | |
exit /b 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment