Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting if a program was run by Visual Studio, as opposed to run from Windows Explorer

Is there a way to detect if your program was loaded through Visual Studio vs. whether it was started as a standalone executable?

Our software has a bug reporting feature to handle unhandled exceptions -- we need to be able to distribute debug builds to our beta testers, but we don't want the bug report to go off when we are in the middle of development, because the Exceptions are a lot more useful if VS catches them with a full stack trace, etc.

Right now, I'm disabling the bug report if Application.ExecutablePath includes bin\Debug or bin\Release, but I figure there is probably a more robust way of detecting whether the program was loaded through VS.

Obviously, we could set up a different build with some preprocessor macros, but for the sake of the question, assume that isn't a possibility -- I don't mind adding code, but I'm trying to make the fewest modifications to the build process, which is why command-line options are kind of a last resort as well.

If it matters, I'm using VS2003/.NET 1.1.

like image 469
Mark Rushakoff Avatar asked Aug 27 '09 18:08

Mark Rushakoff


People also ask

How do I see what processes are running in Visual Studio?

To open the Processes viewFrom the Spy menu, choose Processes. The figure above shows the Processes view with process and thread nodes expanded.

Can you open an EXE in Visual Studio?

In Visual Studio, select File > Open > Project. In the Open Project dialog box, select All Project Files, if not already selected, in the dropdown next to File name. Navigate to the .exe file, select it, and select Open.

How do I run a specific program in Visual Studio?

Run the program To start building the program, press the green Start button on the Visual Studio toolbar, or press F5 or Ctrl+F5. Using the Start button or F5 runs the program under the debugger. Visual Studio attempts to build and run the code in your project.

How do I run a Visual Studio code in release mode?

In Solution Explorer, right-click the project and choose Properties. In the side pane, choose Build (or Compile in Visual Basic). In the Configuration list at the top, choose Debug or Release. Select the Advanced button (or the Advanced Compile Options button in Visual Basic).


1 Answers

If you're doing this to determine if it is in any debugger (clarified by @JaredPar), you can use Debugger.IsAttached in the exception handler.

try {     // ... } catch(Exception ex) {     if (!Debugger.IsAttached)     {         ExceptionHandler.Frob(ex);     }     else     {         throw;     } } 

Alternatively:

public static void Frob(Exception ex) {     if (Debugger.IsAttached)     {         Debugger.Break();     } } 
like image 103
user7116 Avatar answered Oct 06 '22 00:10

user7116