Attaching to a process without a dialog

In https://blogs.msdn.com/shaykatc/archive/2004/04/19/116222.aspx, Shaykat gave one alternative to the ntsd '-pn' option. I figured I would give two more.

Alternative #1 - Attach project. Open the exe as a project (File->Open->Project, then select the exe). Open project properties. Set the 'Attach' setting to 'yes'. Hit F5.

Alternative #2 - command script. It is pretty easy to write a script using tlist.exe that can attach to a process by name. The script is below. Hopefully in some future product, you will even be able to set an option to skip the JIT chooser dialog. Note: This only works for native debugging.

 @echo off
if "%1"=="-?" goto help
if "%1"=="/?" goto help
if "%1"=="" echo The syntax of the command is incorrect.& exit /b -1
if NOT "%2"=="" echo The syntax of the command is incorrect.& exit /b -1

call :find_file tlist.exe
if NOT %ERRORLEVEL%==0 exit /b %ERRORLEVEL%

if not exist "%CommonProgramFiles%\Microsoft Shared\VS7Debug\vs7jit.exe" echo Could not find vs7jit.exe & exit /b 1

setlocal
set __found=0
for /f "tokens=1,2" %%d in ('tlist.exe') do call :parse_process %1 %%e %%d
if %__found%==0 echo Process '%1' is not running
endlocal
exit /b 0

:parse_process
if /i "%1"=="%2" goto run_command
if /i "%1.exe"=="%2" goto run_command
exit /b 0

:run_command
set __found=1
call "%CommonProgramFiles%\Microsoft Shared\VS7Debug\vs7jit.exe" -p %3
exit /b 0

:find_file
if "%~$PATH:1"=="" if "%~z1" == "" echo Error! Could not find %1. & exit /b -1
exit /b 0

:help
echo attach.cmd ^<process_name^>
echo.
echo Debug a process with VS7/VS7.1.   example: attach.cmd notepad.exe
echo.