How to identify the console application? 
Author Message
 How to identify the console application?

Information is not displayed on the screen at all even if
the Console.WriteLine method is used by the Windows
application, and the exception is not generated though it
is also in the document either.
Therefore, I want to know whether the program under
execution is a console application or it is a Windows
application.

Corresponding information was not found in the Process
class and Process.StartupInfo.

Please teach if there is something a good method.



Tue, 02 Mar 2004 12:47:15 GMT  
 How to identify the console application?
Hi:
One of the ways would be if a class inherits from System.Windows.Forms.Form
then its a windows application. If the class inherits System.Web.UI.Page or
UserControl then its a WebForm or the UserControl CodeBehind. Otherwise it
should be a Console Application. If there is a Main method declared, which
does the major operations of the program then its a console application.
Hope this helps,
Priti


Quote:
> Information is not displayed on the screen at all even if
> the Console.WriteLine method is used by the Windows
> application, and the exception is not generated though it
> is also in the document either.
> Therefore, I want to know whether the program under
> execution is a console application or it is a Windows
> application.

> Corresponding information was not found in the Process
> class and Process.StartupInfo.

> Please teach if there is something a good method.



Tue, 02 Mar 2004 23:56:29 GMT  
 How to identify the console application?
Knowning if application runs in Console or GUI subsystem
is very handy when writing .NET libraries.

And up to date, NO function for this was found in .NET?

According Microsoft, the '.subsystem' directive of a
.NET assembly manifest is NOT in the metadata!
So we can't access this with Reflection...

If you don't care about a small helper function
with 3 lines of Win32-Interop, see my workaround below.
[Tested on Win2000SP2 only!]

I propose Microsoft should add a similar function to
 'System.Environment' class.

------------------------------------------------------------------
using System.Runtime.InteropServices;
.....
public static bool IsConsole()
 {
 // get in-memory-pointer of EXE
 IntPtr ptrexe = GetModuleHandle( IntPtr.Zero );

 // msdos header e_lfanew
 int peoff = Marshal.ReadInt32( ptrexe, 0x03c );

 // 4='PE00' + 20=COFF + 68=offsetof:subsystem
 // 3=IMAGE_SUBSYSTEM_WINDOWS_CUI
 return Marshal.ReadInt32( ptrexe, peoff + 4 + 20 + 68 ) == 3;
 }

[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
private static extern IntPtr GetModuleHandle( IntPtr modname );

------------------------------------------------------------------
KB Q90493:
  http://support.microsoft.com/support/kb/articles/Q90/4/93.ASP
EXE file headers:
  http://www.microsoft.com/hwdev/download/hardware/PECOFF.pdf
.NET Tool Developers Guide:
  Partition II Metadata.doc
------------------------------------------------------------------

 NETMaster
 http://www.cetus-links.org/oo_CSharp.html

I've been "encouraged" to share this helpful information from my lawyers:
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use.
? 2001 NETMaster. All rights reserved.

Quote:

> Information is not displayed on the screen at all even if
> the Console.WriteLine method is used by the Windows
> application, and the exception is not generated though it
> is also in the document either.
> Therefore, I want to know whether the program under
> execution is a console application or it is a Windows
> application.

> Corresponding information was not found in the Process
> class and Process.StartupInfo.



Wed, 03 Mar 2004 00:50:53 GMT  
 How to identify the console application?
There really isn't any difference between a Windows Forms application and a
console application. By default, a Windows Forms application builds with
/target:winexe, which suppresses the console window. You can change this if
you want, and use console windows to help debug your Windows Forms
applications.


Quote:
> Hi:
> One of the ways would be if a class inherits from

System.Windows.Forms.Form
Quote:
> then its a windows application. If the class inherits System.Web.UI.Page
or
> UserControl then its a WebForm or the UserControl CodeBehind. Otherwise it
> should be a Console Application. If there is a Main method declared, which
> does the major operations of the program then its a console application.
> Hope this helps,
> Priti



> > Information is not displayed on the screen at all even if
> > the Console.WriteLine method is used by the Windows
> > application, and the exception is not generated though it
> > is also in the document either.
> > Therefore, I want to know whether the program under
> > execution is a console application or it is a Windows
> > application.

> > Corresponding information was not found in the Process
> > class and Process.StartupInfo.

> > Please teach if there is something a good method.



Wed, 03 Mar 2004 02:33:33 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. how to use a console window in a win32 application..-- not console application

2. Identifying if Function Called from Window or Console

3. Executing a console application without it opening a console

4. Starting a console application without the console window

5. Console control in console application

6. console application pauses when mouse clicks inside the console

7. Console o/p from windows application (not in new console)

8. Identify network applications

9. Tool for identifying memory leaks in C++ based application on HP

10. Password problem on console application

11. Managed C++ Empty project console application

12. Com .Net Message Queues and Console applications

 

 
Powered by phpBB® Forum Software