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
303 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
  • 4
  • 3
7 Comments
 
LVL 33

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 33

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
Integrate social media with email signatures

Is your company active on social media? Do you also use email signatures? Including social media icons in your email signature is a great way to get fans for free. Let all your email users know you’re on social media quickly and easily, in a single click.

 

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 33

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 33

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
pdf convertor 7 66
login windows 10 4 42
How to create virtual printer while installing my application 5 24
windows 10 too frequent updates regularly , why? 6 33
A Bare Metal Image backup allows for the restore of an entire system to a similar or dissimilar hardware. They are highly useful for migrations and disaster recovery. Bare Metal Image backups support Full and Incremental backups. Differential backup…
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now