开发者

Which is the proper way to detect if my app is running from Visual Studio?

开发者 https://www.devze.com 2023-04-03 04:25 出处:网络
I need to detect if my application is running under the Visual Studio IDE (2005, 2008 and 2010). The reason is that I distribute developer licenses of my DLL, so I need detect if the DLL is running u

I need to detect if my application is running under the Visual Studio IDE (2005, 2008 and 2010).

The reason is that I distribute developer licenses of my DLL, so I need detect if the DLL is running under VS to check that the license exists.

Currently, I'm using the System.Diagnostics.Debugger.IsAttached property and checking if the parent process of my application is devenv.exe. So far this works okay.

I'm wondering if t开发者_如何学Chis is the proper way, or am I missing something?


I've seen MSDN examples use that, and I'm unaware of any other way to check, so I would say that you are doing it correctly.


You could provide a command line argument to the program on execution from the IDE, something akin to a '-Debug' argument.

This would be done via the toolbar submenu Project->Properties->Debug->Start Options, and typing -Debug or whatever argument name you'd prefer, and then checking for it in your Main(string[] args) function, the simplest way being with the 'Contains' function:

static void Main(string[] args)
{
   bool isDebugMode = args.Contains("-debug");
}

However, if this is merely to prevent developers from calling the DLL unlicensed with their own programs, they may be able to bypass the system by starting the executable from outside of the IDE, then attaching the debugger after your checking step has been performed... In this case, I would suggest an alternate route of licensing.

0

精彩评论

暂无评论...
验证码 换一张
取 消