all groups > visual studio .net debugging > september 2006 >
You're in the

visual studio .net debugging

group:

Am I running from studio?


Am I running from studio? Aurin
9/29/2006 10:07:01 AM
visual studio .net debugging:
I there a way that I can determine whether or not a Windows.Forms app is
running from Studio? i.e. did the app start via the Start button in Studio
Re: Am I running from studio? Eric Moreau
9/30/2006 8:57:08 AM
if debugger.isattached then
'you are running from within the IDE
end if

--


HTH

Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
S2i web inc. (www.s2i.com)
http://emoreau.s2i.com/

[quoted text, click to view]

RE: Am I running from studio? jetan NO[at]SPAM online.microsoft.com (
10/2/2006 3:26:25 AM
Hi Aurin,

If you just wanted to determine if your winform application is debugged by
a debugger, then you may follow Eric's suggestion of checking
System.Diagnostics.Debugger.IsAttached static property to determine if a
debugger is attaching to your application.

However, this solution can only determine the debugging status, so if
another user uses windbg or other valid debuggers to lauch/attach your
winform application, your application will also report "true" for
Debugger.IsAttached property.

The only reliable solution to check if the debugger is Visual Studio is
checking the current winform application's parent process. Once we got the
parent process ID, we can determine if the parent process main module is
the "devenv.exe". However, current .Net FCL did not encapsulate the parent
process information in the Process class, we have to p/invoke the win32 API
to get this done. In win32 world, we have 2 ways to obtain the parent
process ID:
1. Using Process32First/Process32Next APIs and retrieve the parent process
ID in PROCESSENTRY32.th32ParentProcessID field.
2. Using the NtQueryInformationProcess API, and the
"InheritedFromUniqueProcessId" field in ProcessBasicInformation structure
is the parent process ID. The article below demonstrates this technology:
"Retrieving the parent of a process (WinNT)"
http://www.codeguru.com/cpp/w-p/win32/article.php/c1437/

Sorry, I can not find a C# code snippet to use these 2 ways, if you have
problem of doing p/invoke, please feel free to tell me, thanks.

After getting the parent process id, you may use Process.GetProcessById
Net static method to obtain a Process object. Then
Process.MainModule.ModuleName will report the parent process main module
name. Comparing it with "devenv.exe" will tell you if the parent process is
Visual Studio process.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
AddThis Social Bookmark Button