Reputation: 858
is there a way to detect inside the component in C# if the application that uses this component is running in console application or others?
Upvotes: 2
Views: 168
Reputation: 6159
The information you need is a property of your exe assembly. If you use a tool such as ildasm.exe to view your assembly's manifest, you can see the .subsystem property that indicates the type of execution environment that launches your Main method.
However, it seems like Reflection doesn't expose this info directly.
The code in the following link contains an example for how to read the .exe file itself and detect this infromation:
http://blogs.msdn.com/b/kstanton/archive/2004/03/31/105060.aspx
I hope this helped.
Upvotes: 1
Reputation: 74280
Use Environment.UserInteractive
. If true
you are in a console. If false
you could be in a service.
Upvotes: 8
Reputation: 7326
Reflection is one of the first places I would look -
http://msdn.microsoft.com/en-us/library/system.reflection.assembly.getexecutingassembly.aspx
Q: How "sure" do you need to be?
Upvotes: 0
Reputation: 3917
Please see this example for your solution: http://weblogs.asp.net/whaggard/archive/2004/08/30/223020.aspx
Upvotes: 1