In an application I am making, I want to know when a user copies a file or clicks the start button. Those actions would be considered too trivial but they carry some importance in my application.
Yesterday, I received a comment Getting notified of any action taken by user on windows on a similar question so I am hesitating to switch the entire auditing infrastructure.
Going as per explanation of eventtriggers http://technet.microsoft.com/en-us/library/bb490901.aspx
Creates a new event trigger that monitors and acts upon the occurrence
of log events of given criteria.
I am not sure what the limits of eventtriggers and how it can help me achieve my goal without so much overhead. Can eventtriggers help me set a trigger that notifies me when the start button is clicked?.
Not possible, to my knowledge, unless you poll to find out the status. This example was already brought up in a previous question on SO:
How can I detect when the Windows 7 start menu opens
Theoretically you could write something that lives on a different thread that queries the start menu at given intervals. Then, if the start menu was detected as open you could trigger the code you want done. Just a thought...
Related
I have a very simple method that writes a file locally but I only want to fire it if the user looks like they are going to drop outside of the app because firing it every time they start dragging would result in lots of unnecessary files being written.
So my question is: if a user drags something within the app outside of the app, is it possible to detect when they drag over a valid drop target (e.g. the desktop or windows explorer)?
EDIT: At a more general level, my question is: how can I respond to mouse/drag events that occur outside of my app?
Not entirely sure what it is you're exactly trying to achieve, but this may help:
WPF: Drag and drop virtual files into Windows explorer
For the most part the drag / drop events should fire regardless of where you're dropping to (I think), but you can certainly be notified when a drop has been performed.
As #Quarzy stated, unless you're in communication with the other app, there may be no direct way of testing for data that the underlying windows drag / drop system doesn't expose.
More specifically that question points to this article: http://blogs.msdn.com/b/delay/archive/2009/11/04/creating-something-from-nothing-asynchronously-developer-friendly-virtual-file-implementation-for-net-improved.aspx
I post this purely because I wonder if maybe it may lead to other things, apart from that you might be able to get the Hwnd of the control under the cursor - possibly http://social.msdn.microsoft.com/Forums/windows/en-US/3df9fc84-4020-4ae1-8b4f-942bce65568f/find-the-object-under-the-mouse?forum=winforms as a starting point.
There may then be a way to query whether that particular control is a valid drop target through interop as well.
Good luck!
This might be a possible answer for your question: Register a global hook to detect whether mouse dragging files/text
How ever the following suggestion might help (Require you to create c++ external lib):
Capture other possible processes window message (Global hook WH_GETMESSAGE) (See this link How to Create a global WH_GETMESSAGE HOOK without DLL)
Listen for WM_DROPFILES
see the following link: http://www.experts-exchange.com/Programming/Languages/CPP/Q_10203575.html
You have also an helping answer here How can I capture mouse events that occur outside of a (WPF) window?
But I do not see any way to detect if the target is valid, as long as you have no communication with the potential targets.
I'm currently using a delegate to poll the current active control from the currently focused external form every few milliseconds, which works badly.
The title of the question is somewhat confusing, as this does not actually have anything to do with Application.OpenForms. That property just exposes a collection of all the currently open forms. If a new form is opened that had not previously been opened, it will be added to the collection. But the operating system allows only one active window at a time on the desktop, so what you really want is to get notified when the active window changes. Polling will work for this, but it isn't a good solution.
You will either need to install a global hook (WH_CBT is likely the one you want), or take advantage of the WinEvents infrastructure (via the SetWinEventHook function) intended for accessibility tools. Both of these will provide you with a notification when the active window changes. Of course, their scope won't be limited to the application that you are testing. You'll get notification when the active window on the desktop changes to any other window. It will be up to you to filter that down to the application you care about.
I don't have time at the moment to translate any of the required code to C#/.NET, but you can probably find it somewhere online, once you know what to search for. Additionally, WinEvents is already wrapped for you in the System.Windows.Automation namespace.
I have explained my project below and asked some questions with "My Question-" tag.
I have working on a project. At the time of windows logon page if I enter a wrong password my cam should take the picture, If I open regedit my system should take a screen shot and save these images in C:\Windows\system32\new folder (I tried a lot making this work with the help of manifest files but failed everytime) and emails it whenever finds an internet connection
I have a form based app because I didn't find any other way to capture image from webcam directly but taking input from pictureBox1.Image.
My cam, screenshot,email (didn't find a way to autocheck if has internet connection available or not) and 3 events checker for "firewall enable/disable, windows logon failure , regedit event called" are done and they are working good.
What I need to do is to assemble these codes to work as an app and running in the background continuously from the time of windows startup to shutdown
To validate positive events I need to make a desktop based db ("My Question"- still figuring out either to choose sql or localdatabase in c#. Please also tell me a suitable solution.I have to delete all the entries from the db once a day is over). The db would contain the following columns (event id, event name, event timestamp).
I want my app to check if this very event exists in the db then it should ignore the event generated on windows event log else it should make a new row with the db columns and it should do the following actions based on the event like taking webcam pic or screenshot.
"My Question"- I want my app to be live at the time of windows logon page. A lot of programs start later when you are authenticated but I need my program to be live at the time of logon page. Do I have to make 1 or many services? or multi-threaded? because in the typical form based app you can only call one function at a time and wait for it to return something or perform some task/action and then you call the second third whatever.
"My Question"- Do I need to use the backgroundworker in c#
Please help!
You have a lot of things going on here for one question.
You can put all your code in a background service that gets started at boot time. There is a walkthrough here to show you how to do that (along with a million other sites).
Addressing some of the other issues you listed:
Google is your friend...
Webcam - Found a quick reference here and here
File Modification - Another SO thread here
SQL vs. Other Database - Not sure you need anything elaborate here, probably something you can put together pretty quickly. Another SO thread addressing that here
Good Luck!
I am looking for advice and help regarding a specific use case of an application.
Here's the use case:
A user our our WPF application goes crazy and starts clicking all over, triggering a number of events before the first (or previous) event(s) have to finish.
Currently, WPF queues any and all clicks and queues them for sequential execution. Ideally we would like to queue up to 3 events and drop and disregard any and all clicks (user interactions) after the first 3.
What would be the best approach to solving this issue, what is the best practice for this use case. Any documentation, code and/or help would be much appreciated.
Since this really is a windows issue and not specifically a WPF issue, the only thing I can think of is hooking the message queue and discarding clicks within a certain time unless you write specific handlers into each control. The other option is to write the application such that feedback is provided to the user during an operation and input is disabled.
What does WPF use to capture mouse and keyboard input?
If you'd use MVVM all UI actions are bound to ViewModel commands or properties. In the ViewModel you'd have full control over how many and how frequently you want to process what comes from the UI. It will probably involve some sort of producer consumer queue.
Also if your user actions block the UI, you need to process them outside the UI thread as much as possible.
At my workplace, I need to create a questionnaire that is compulsory for the user to fill out. The aim is to make it as non-intrusive to the user as possible and link it to their Windows account. The results will then be stored in a database where reports can be generated off of the responses.
The suggestion was to load the questionnaire at login time, i.e. when the user logs onto the computer. I would have to make the window exclusive so that no other windows could be interacted with.
My question how would I go about doing this? Could this be done with WPF or would I need XNA or something similar?
Also, are there any other suggestions on how I could meet all the criteria with a different implementation?
Is there a way to run/activate an application at screen unlock?
You can create an app with WinForms or WPF. I don't know about XNA. :) And you can load it on startup; by using Registry. You may need to manually disable ALT + Tab, using API, to disable the interaction between other windows.
First off, it appears you may have conflicting requirements - "non-intrusive" and "compulsory" - to a user any interruption can be considered a violation of their sacred time :)
I would use a Maximized WPF Window that allows transparency, has no window style, fairly transparent to look like the background is disabled. The "form" area would be centered on the screen. The form, once filled out, would close and set a per-user state in a settings.config file to ensure the next time the user logs in it doesn't show up again.
Anuraj has it right to attempt to disable as much interaction as possible via the supression of special keystrokes.
I would suppress the keystrokes by marking the KeyEventArgs as handled upon the raising of the PreviewKeyDown event.
I've never done this on multiple monitors, though, don't know how that would look.
Compulsory is done by, as you say linking it to their domain accounts, and then giving anyone a written warning who has not completed the questionnaire in some time frame.
If you are not willing to back your "compulsory" requirements with actual discipline procedures then implementing technical obstructions is a waste of time. With discipline procedures in place, technical obstructions are unnecessary to achieve compliance.
The actual implementation would probably be best done on the corporate intranet server as a web-form.
This of course requires that the company is mature enough to be using a central login server of some kind (domain controller if windows) and has a corporate intranet.
Now is a good time to start perhaps.