Disable start menu from opening with keyboard combo? - c#

How do I prevent the start menu from opening by using the keyboard shortcuts / combo (aka windows key and CTRL + ESC) ?
I am able to hide the taskbar, and receive the keys but I don't know how do I disable them, I need to disable it until the user is authenticated with the system.
Is there a policy I can use to disable them or how do I do it ?

This sounds like a job for hooks
http://www.codeproject.com/KB/cs/globalhook.aspx
Update:
From MSDN:
A global hook monitors messages for
all threads in the same desktop as the
calling thread. A thread-specific hook
monitors messages for only an
individual thread. A global hook
procedure can be called in the context
of any application in the same desktop
as the calling thread, so the
procedure must be in a separate DLL
module. A thread-specific hook
procedure is called only in the
context of the associated thread.
In other words, if you use a global hook like in the link, you can capture system events and either process them like normal events or suppress them.
Another Update: Here is another example which was created with the Windows key and CTRL+ESC in mind.

Would the example here be what you are looking for?
http://geekswithblogs.net/aghausman/archive/2009/04/26/disable-special-keys-in-win-app-c.aspx

I've never done this myself, but I heard that you should replace explorer shell with your program for that kind of application. Look into it, maybe it's the way to go..
http://www.ehow.com/how_5688935_replace-window-shells.html
https://groups.google.com/group/microsoft.public.windows.server.scripting/browse_frm/thread/fa1760ad06c77259?hl=en&pli=1

Related

How to prevent a remote process from being closed in Windows?

There is a program which I can't modify it's code having been opened. I want to create a "watcher" to hook the closing event of that program in order to make the main window of the program hidden rather than being closed when users try to close that program.
I have googled it and someone says hook the API named OpenProcess would work. I tried using a C# lib called "EasyHook" and succesfully inject a remote process and hook MessageBeep API. Then I tried hooking OpenProcess and TerminateProcess, but the hooked methods of those two methods were never called.
So what is the proper method should I hook or is there any other way can realize my purpose? If there is no way to prevent the process being terminated with task manager, is there any tricks like hooking the close button of the window etc.?
PS. I don't know kernel programing of Windows and driver programing, so I want to realize it in user mode if it is possible.
I want to create a "watcher" to hook the closing event of that program in order to make the main window of the program hidden rather than being closed when users try to close that program.
There is no process close event that you can hook. However, for GUI programs, there are WM_CLOSE and WM_SYSCOMMAND|SC_CLOSE window messages that you can intercept with SetWindowsHookEx().
I have googled it and someone says hook the API named OpenProcess would work.
Whoever said that hooking OpenProcess() is the solution to this was either mistaken, or you misread what that hook was actually being used for.
I tried using a C# lib called "EasyHook" and succesfully inject a remote process and hook MessageBeep API. Then I tried hooking OpenProcess and TerminateProcess, but the hooked methods of those two methods were never called.
Of course, because you tried to hook them in the process that is being terminated, but that is not where they are called from, they are called in the process that is doing the terminating (ie, in Task Manager itself).
If there is no way to prevent the process being terminated with task manager
If the brute force "End Process (Tree)" option is used, then there is no option to catch/block that. The "End Task" option on the "Application" tab tries to perform a graceful termination using window messages before it resorts to brute force.
is there any tricks like hooking the close button of the window etc.?
See my first comment above.

c# detect which messagebox (originated in another app) button has been pressed

Another application displays a messagebox (with a unique text inside it), user chooses Yes/No.
How to detect what he pressed in c#? (best in .Net up to 3.5). I could do polling with FindWindowEx (on another thread) but how to detect what button had been pressed? Also I don't think polling is the best way to do the job.
I need to know what the user has chosen in another app, so I can react accordingly in my own app. I don't have access to the other app's source code. Also to make it clear I don't want to click any of the buttons myself. I'm not afraid of a bit of c++, winapi and pinvoke
To monitor UI events in another application you can use UI Automation. To solve your specific problem you need to subscribe to a particular event (see Subscribing to UI Automation Events). To do so call IUIAutomation::AddAutomationEventHandler with a UIA_Invoke_InvokedEventId Event Identifier.
While UI Automation can be used to solve your problem, it is an assistive technology, mainly to enable accessibility needs and automated UI testing.
You could use either Anonymous or Named Pipes or WCF(Windows Communications Foundation).

Creating a Process in the background that will listen to keyboard

I have a project that runs in the background in a different process, I want it to be able to react to keyboard everywhere, for example I run the project, and afterwards I do other stuff in the computer such as browsing, facebook, watching movies etc.., and every time I press F9 I want my project to show up. Same as how you press a combination of keys to invoke Babylon... I want to implement it in C#, I have no idea how to begin.
You can register a hotkey with the RegisterHotKey API function. You can see an example of its usage from C# here.
I think you need to write a system-wide keyboard hook, check here for details:
https://stackoverflow.com/a/1764434/559144
How do I grab events for all applications? An example system-wide hook.

Send keystroke to non-foreground window

According to this article on msdn, it is possible to set a specific window as the foreground window, and then send keystrokes to it... but I need to send keystrokes to a window in the background, so that whatever the user is doing can continue uninterrupted.
Maybe you should just catch the keystrokes in your foreground window and pass them to the background window (delegate). Or if they are somewhat complex you could use global hotkeys. Anyways passing the keys from your foreground form to your background form should be the better solution.
I found a nice example it's not about hotkeys but the concept should apply in your case as well.
http://www.codeproject.com/KB/cs/pass_data_between_forms.aspx
So basically a keystroke listener? Java has a robot class that listens for keystrokes and can act upon them (ex. me typing "Hello World" and the class will automatically write that to a file or other window).
I've created something similar in the past. You can create a java program to run in the background in a constant while loop and just listen for keystrokes. Set the program to write each keystroke to a file or specific place. Because this is a short while loop and only reacts when a key is pressed, it takes up almost no processing power and does not affect the performance of the program in the foreground.
I do this with shortcut keys. I have an application that has multiple child windows along the side. The main window enables the Form.KeyPreview property of the child windows and then registers for the appropriate event (KeyPress, KeyDown or KeyUp) on that child window. With this setup the main window can process all the keys from the child windows.
The technique I've used on Windows Mobile/CE is to hook the keyboard and then simply use PostMessage() to send them to the target window to be handled as normal. This technique should also work on the desktop. There are several examples on Code Project of hooking the keyboard - http://www.codeproject.com/KB/system/globalsystemhook.aspx. Your question was not clear if the foreground window was part of your application or not. If it is, wouldn't you simply subscribe to one of foreground form key events from the background form?

How to execute some code everytime an application window (other processes) is opening?

I am trying to track visible windows from all currently running processes. My program interacts with these windows and the faster it can detect them the better. My goal is to move visible windows to a certain location on screen before they even draw in the default position if that is possible. If not I want to move them as quickly as possible after they are created.
Right now I enumerate through the visble windows using EnumWindows (p/invoked from user32.dll) in a loop with as small a delay in between iterations as I can justify.
I am looking for a method to hook into 'something' which will allow me to wait for a 'window opening up' event to fire instead of constantly polling.
Are there any methods to achieve this?
You need the SetWindowsHookEx() API function, setting a WH_SHELL hook. The callback gets a HSHELL_WINDOWCREATED notification when a new toplevel window is created.
This is a global hook, you cannot write the code for this hook in C#. It requires a DLL that can be injected in a process, the CLR cannot be initialized properly to support managed code. You'll need an unmanaged DLL to get the job done, this project offers one.

Categories