Search code examples
visual-studio-debugging

Visual Studio Just-In-Time debugger, how to choose current running instance?


When your program asserts, JIT pops up and asks you if you wish to close or debug the program. After choosing debug, you need to confirm yes, debug. Then, you need to choose a visual studio from the list, which is most likely the current running instance. How do you automate this procedure?


Solution

  • I used AutoHotKey:

    ; Auto-click jit debug pop-up. Run the script as admin. 
    Loop,
    {
        WinWait, Visual Studio Just-In-Time Debugger
        IfWinExist, Visual Studio Just-In-Time Debugger
        {
            ;MsgBox, here
            WinActivate, Visual Studio Just-In-Time Debugger
    
            ; click the yes button
            SetControlDelay -1
            ControlClick, Button1
    
            ; choose instance from the list
            WinWait, Choose Just-In-Time Debugger
            WinActivate, Choose Just-In-Time Debugger
            ;ControlGet, lb1, Hwnd, , ListBox1
            ;msgbox, %lb1%
            ControlGet, items, List, , ListBox1
            Loop, Parse, items, `n
            {
                ;MsgBox, Item number %A_Index% is %A_LoopField%.
                IfInString, A_LoopField, administrator 
                {
                    ;MsgBox, found
                    Control, ChooseString, %A_LoopField%, ListBox1
                    break
                }
            }
    
        }    
    }
    

    In the listbox, I'm looking for an item that contains the substring 'administrator', but you can change that.