Disable ALT+F4 for C# Console Application? - c#

im using c# .net 2.0 Console Application.
How can i prevent my console application from ALT+F4 shortcut?
is there any way to do that?
everywhere there is winform solution.
I need console app solution.
please help me

#Jeroen Mostert:
i found a final working solution from prevent exiting console app by the user.
Everybody says its not possible. But yes it possible with simple tweak.
Here we go
using C#
RegistryKey objRegistryKey = Registry.CurrentUser.CreateSubKey(#"Console");
objRegistryKey.SetValue("AllowAltF4Close", "0" , RegistryValueKind.DWord);
I cant post my full code here due to copyright
but this code works within my application. I tried to make a sample but that not works. But within my full application this works and Nobody can close by pressing ALT+F4.
this is a real solution for all. I don't know which part is required within my all code to make sample.
but this works.
you can just change value 0 to 1 to enable ALT+F4
CMD will not closing if you use this code. try code and launch another cmd.
i dont need to launch another CMD. within my code that works for itself.

Related

How to communicate between two different applications (Web Application and Console Application) using Ctr+c , Ctr+v , Entre [duplicate]

I am developing a console application in C#, and was wondering if there was a way to get the "copy-paste" or "mark-paste" functionality into my application, similar or identical to that of the standard Windows command prompt. Is this a wild goose chase or a simple application variable?
I've copied text from the Console window and pasted it into another source many times.
It's there as default in a Console application;
Right click the console border:
Select Edit > Mark:
Drag over the text you want using the mouse (Or use the arrow keys) to select the text you want:
Again, right click on the console border and select Edit > Copy:
From here you can paste it into another application as you would with any other text.
This was taken from a C# Console application and the only code entered was the command to write to the console, no settings were changed.
Hope this helps!
Thank you Sean for making me realize the complete idiocy of this question. Let me be an example to others to not jump on the conclusion train.
Sean pointed out that "copy-paste can be done using cmd.exe's built-in functionality", making me recognize that, yes, absolutely duh, when you run your command line application in Windows it already has this functionality available.
I erred by jumping to conclusions, for I was doing all my initial testing with the DEBUG execution through the IDE, and vshost does not give you that functionality.
A quick "Start Without Debugging" revealed my short-sightedness.
I don't know why this isn't included in any answer, but as Robert H. stated in a comment, this is absolutely useful information, in case you came here by searching for this problem in a VisualStudio environment:
Run a console app in the debugger (F5). You cannot copy or paste.
Run it outside the debugger (Control + F5). Now, you can copy and paste.
Worked like a charm for me. Thanks Robert H.!
To clarify, is the default command prompt behavior not working at all for you, or just not how you want it to?
From what I understand, it is the terminal implementation that supplies the copy/paste behavior, and what it provides doesn't match rest of Windows. To change this behavior, you'd have to switch the program that implements the terminal. Here are a couple programs that come up on a google search for "command prompt replacement":
http://www.powercmd.com/
http://sourceforge.net/projects/console/
Of those two, I think one of my friends at work tried "Console". It did enough of what he wanted that he didn't feel the need to keep looking.
If you just want your output for this specific program to work more like the rest of Windows, your other choice is to make it a Windows program.
Edit: Fixed the URL to Console. Was posting to someone's blog that linked to it, before :)
Maybe I am late but there is a shortcut for pasting text in Console Window in c#. Press Alt+Space then 'E' then 'P' and there you have your text pasted in the Console Window

[C#/VB.NET]Communicating with closed source WPF Application

I've got a question regarding communcation with another application. I wrote a little application that checks if specific persons play a specific game (League of Legends) and if so, it creates something called the spectator code which looks like this:
"C:\Riot Games\League of Legends\RADS\solutions\lol_game_client_sln\releases\0.0.1.15\deploy\League of Legends.exe" "8394" "LoLLauncher.exe" "" "spectator spectator.eu.lol.riotgames.com:8088 nQCxZ8ayLm369T1DwEejG/QlEoR+JyZK 1407774989 EUW1"
In another application which is NOT developed by me called "BaronReplays" (http://puu.sh/7VBFj.png) (a WPF application) you can enter this code under File (http://puu.sh/7VBEM.jpg) -> Analyze Command and enter the Code (http://puu.sh/7VBGD.png), after that click ok. Then this game will be recorded. I want to automate the process of entering this code in my application, so that my application sends the code to BaronReplays (without it being maximized and using SendKeys). I tried SendMessage, but that didn't work out because the keys aren't recognized by BaronReplays... Do you think there's any other way to do what I want to do?
There is another way... As the WPF application is coded with the .NET framework, it is compiled to MSIL (Microsoft Intermediate Language). This means you can use a decompiler such as ILSpy to decompile and view the code of BaronReplays. This will give you some idea of how BaronReplays works so you can implement the same ideas into your own code project...
Hope this helped!
Rodit

Finding out if the user manually closed the console window by clicking the red X in C#

I'm working on a project that calls a console window to process some data based on passed in arguments. What I would like to know is how I can check to see if the user clicked on the red X within the console app. Is there an event I need to handle? Any advice would be greatly appreciated. This is being done using the .NET framework 3.5 using VS2005. Thanks.
Use SetConsoleCtrlHandler, C# example here.

How to send function keypress (F1..F12) to a console app in .NET

I am writing a windowed .NET app in C#, which runs a third party console application via the Process class, as hidden as possible (CreateNoWindow, RedirectStandardOutput, etc.).
I've redirected it's StandardInput, so I can write whatever string I want, but not function keys or other type of special keys, as they don't have a character representation. As for me, I have to send keys F1 to F4 to the console app. The solutions I've found are for windowed app (PostMessage, SendMessage).
How can I do this for my console application?
Is there anything to do with the Handle of the Process?
You can't. Function keys cannot work with stdin, an app has to call ReadConsoleInput() to be able to detect them. That no longer works when you start the process without a console window.
Sendkeys.SendWait may solve your problem.
Does SendKeys work ("{F1}")? (the console will have to be active, though).
This isn't directly an answer to your question, but have you considered using MSMQ?
If your windowed application can receive those key-presses, it could pass that fact on to your console application using MSMQ. You may not have to actually pass the key-press, just the the fact that they were pressed.
I have found this techrepublic article helpful in getting the basics of MSMQ working.

What happened to the context menu in my console application?

Was creating a simple console application to do some prototyping and was shocked to see that the right-click/context menu is missing from a standard .NET console app!
I'm unable to find any information about this, and intellisense isn't helping.
So what happened to it? Can I get it back? And if not, how can I configure my console application to treat ctrl-c/ctrl-v as standard?
This is a windows console settings thing. Right click on the task bar of the app, click Properties and check / uncheck quick edit mode.
Also there is no way to get Ctr-C Ctrl-V working in console apps (as far as I know)
Context menu doesn't show up when you right click on the console app body (not the title bar) when VS debugger is attached.

Categories