3

I am using process.Start(); to start a batch file. The CMD windows appears fine and works perfectly. How can I disable the controlbox (minimize, maximize, close) on the upper right of the cmd window progmatically. I wish for the CMD window to be displayed, but prevent the user from closing it using the X button.

Thanks!

bulltorious
  • 7,769
  • 4
  • 49
  • 78
  • 1
    Good question, I wish it can be done, but I don't think so. Probably the only and not good option is to have an application that redirects the std in/out to it and emulates a console window for you. – kenny Apr 04 '11 at 14:45
  • Simply disabling the close button won't prevent the user from closing it. Ctrl+C is another way, along with right-clicking on the taskbar icon, or using Task Manager. How is your application set up? What exactly are you trying to do? You might be able to use [`SetConsoleCtrlHandler`](http://msdn.microsoft.com/en-us/library/ms686016.aspx). – Cody Gray - on strike Apr 04 '11 at 14:47
  • 4
    This is utterly pointless, the user has ways to close the window that cannot be stopped. Stop treating your users like idiots and they'll return the favor by leaving the program running. – Hans Passant Apr 04 '11 at 14:47
  • "Stop treating your users like idiots..." - LOL – bulltorious Apr 04 '11 at 14:55
  • 1
    If you want to have absolute control without hacking in the other process window, maybe you could try other solutions: parsing the batch file and translate it into c# command or use directly c# script to do what you want. It probably takes more time to implement one of these solution than hacking, but at least it's "cleaner". – Sauleil Apr 04 '11 at 15:04

1 Answers1

2

Look here:How to disable the Close button on the title bar of a console application...

It applies to any console (even the one opened with process.Start();).It's complicated but I think it's the only method available.

manji
  • 47,442
  • 5
  • 96
  • 103