Solved

ConsoleNoClose.exe for Console Apps on Windows to eliminate the X to Close - Has anyone used this app and could you give me some feedback on the results?

Posted on 2014-10-20
7
328 Views
Last Modified: 2014-10-30
I have a windows Console application that runs on XP, Win7, Win8, WinServer2003+

It has always been a problem when users us the X in the upper right to close the application.  I saw a posting about this utility called ConsoleNoClose.exe which runs in the background and will disable the X to close.  

I wondered if any expert that watches this list has used this utility and if there are any gotcha's that might be an issue.

When I searched the web, I saw more hits about Removing the utility than installing and it got me a bit worried that the use of the utility caused issues that I might not be anticipating.

If you have a better solution to eliminating the X in a Windows Console application, I would be glad to know what else I might investigate.
0
Comment
Question by:nlpalmquist
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 34

Expert Comment

by:it_saige
ID: 40393186
Is this your console application (something you wrote) or a third-party console application?

-saige-
0
 

Author Comment

by:nlpalmquist
ID: 40395649
A custom application that I wrote.  It runs as a Microsoft 32bit console application in the environment that we are considering using this utility.
0
 
LVL 34

Expert Comment

by:it_saige
ID: 40395740
If the environment supports using a windows form application and the user does not need to interact with the console environment, you could change your application to be a windows form application that just displays the output returned from the console environment.

If this is a possibility, let me know, I can provide some sample code.

-saige-
0
Flexible connectivity for any environment

The KE6900 series can extend and deploy computers with high definition displays across multiple stations in a variety of applications that suit any environment. Expand computer use to stations across multiple rooms with dynamic access.

 

Author Comment

by:nlpalmquist
ID: 40404883
That Change is not possible. But thank you for your responses.  I think I will recommend that we do not use this utility, as much as it might be helpful for poorly trained users.
0
 
LVL 34

Expert Comment

by:it_saige
ID: 40404985
I understand.  Otherwise, this is the best I could come up with.  It does not remove the close button but it does disable it:
using System;
using System.Runtime.InteropServices;

public class Program
{
	public static void Main()
	{
		NativeMethods.DeleteMenu(NativeMethods.GetSystemMenu(NativeMethods.GetConsoleWindow(), false), NativeMethods.SC_CLOSE, NativeMethods.MF_BYCOMMAND);
		Console.ReadLine();
	}
}

public static class NativeMethods
{
	public const int MF_BYCOMMAND = 0x00000000;
	public const int SC_CLOSE = 0xF060;

	[DllImport("user32.dll")]
	public static extern int DeleteMenu(IntPtr hMenu, int nPosition, int wFlags);

	[DllImport("kernel32.dll", ExactSpelling = true)]
	public static extern IntPtr GetConsoleWindow();

	[DllImport("user32.dll")]
	public static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
}

Open in new window


In my testing, the Close button does not show as disabled, but hitting the close button does nothing.  Also Alt-F4 does not work nor does the close option show in the system taskbar menu, e.g -Close button is not marked as disabled but clicking does not close the console application.Right-clicking on the taskbar icon, does not show a close option.The same is true by right-clicking on the menu bar of the console window.  No close option.
0
 
LVL 34

Accepted Solution

by:
it_saige earned 500 total points
ID: 40405010
Ok I found a way to gray the Close button as well (this code also includes disabling the minimize and maximize options and removing their menu entries):
using System;
using System.Runtime.InteropServices;

public class Program
{
	public static void Main()
	{
		NativeMethods.EnableMenuItem(NativeMethods.GetSystemMenu(NativeMethods.GetConsoleWindow(), false), NativeMethods.SC_CLOSE, NativeMethods.MF_GRAYED); 
		NativeMethods.DeleteMenu(NativeMethods.GetSystemMenu(NativeMethods.GetConsoleWindow(), false), NativeMethods.SC_CLOSE, NativeMethods.MF_BYCOMMAND);
		NativeMethods.EnableMenuItem(NativeMethods.GetSystemMenu(NativeMethods.GetConsoleWindow(), false), NativeMethods.SC_MAXIMIZE, NativeMethods.MF_GRAYED);
		NativeMethods.DeleteMenu(NativeMethods.GetSystemMenu(NativeMethods.GetConsoleWindow(), false), NativeMethods.SC_MAXIMIZE, NativeMethods.MF_BYCOMMAND);
		NativeMethods.EnableMenuItem(NativeMethods.GetSystemMenu(NativeMethods.GetConsoleWindow(), false), NativeMethods.SC_MINIMIZE, NativeMethods.MF_GRAYED);
		NativeMethods.DeleteMenu(NativeMethods.GetSystemMenu(NativeMethods.GetConsoleWindow(), false), NativeMethods.SC_MINIMIZE, NativeMethods.MF_BYCOMMAND);
		Console.ReadLine();
	}
}

public static class NativeMethods
{
	public const int MF_BYCOMMAND = 0x00000000;
	public const int MF_GRAYED = 0x1;
	public const int MF_ENABLED = 0x00000000;
	public const int MF_DISABLED = 0x00000002;
	public const int SC_CLOSE = 0xF060;
	public const int SC_MINIMIZE = 0xF020; //for minimize button on forms
	public const int SC_MAXIMIZE = 0xF030; //for maximize button on forms

	[DllImport("user32.dll")]
	public static extern int DeleteMenu(IntPtr hMenu, int nPosition, int wFlags);

	[DllImport("user32.dll")]
	public static extern int EnableMenuItem(IntPtr hMenu, int tItem, int tStatus);

	[DllImport("kernel32.dll", ExactSpelling = true)]
	public static extern IntPtr GetConsoleWindow();

	[DllImport("user32.dll")]
	public static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
}

Open in new window

Produces the following -Disabled and greyed out close button.  Minimize and maximize show as grey but are still selectable, again they do not acutally function.Close, Minimize and Maximize options do not appear on the menu either.
-saige-
0
 

Author Closing Comment

by:nlpalmquist
ID: 40414013
I appreciate your suggestions.  Thank you very much.
0

Featured Post

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
There are many software programs on offer that will claim to magically speed up your computer. The best advice I can give you is to avoid them like the plague, because they will often cause far more problems than they solve. Try some of these "do it…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question