System Idle Detection - c#

I want to detect if the system is idle, ie: user not using the system. I want it like the Windows Live Messenger it changes automatically to away when I leave the computer for a time like 3 minutes, I want to set this time within the code.
I`m working on the WPF under C# environment using both visual studio 2008 and 2010 so if here is a way that work on both that`ll be great.

There's an article on CodeProject that should get you started.

I've provided an answer for detecting inactivity and activity in WPF and it might be interesting for you:
WPF inactivity and activity

Windows does provide some API's for that, although they're not reliable for multiple sessions or something like that.
What I used is a hook to WW_MOUSE_LL with SetWindowsHookEx(); That's in C. Must be pretty similar for C#. Basicaly whenever the user does something with the mouse, the timer starts from 0 again, and if the timer reaches some value, you do something upon that(act-if system is idle). You could also hook it with the keyboard, in case the user is just typing, and share the timer between the two threads. It works wonderful for me.

Related

How to programmatically add/modify/delete available display settings (width, height, refresh rate)?

I want to code (in C#) a tool to add/modify/delete some of the available Windows display configurations (width, height and refresh rate).
Can this be done programmatically? I've spent many hours trying to find something about this online but had no luck.
The reason i want it is because of some older full screen games that keep setting the refresh rate back to 60hz from whatever it were when the game started (120hz in my case). I can solve that problem using Alt-Tab twice but I rather want to just limit the available display configurations (or change the refresh rate for some of them) instead.
Before considering all this I've tried to solve my problem with these attempts:
Intercepting the keyboard (using this class Global keyboard capture in C# application) and then attempt a force display change when a hotkey it pressed. It works fine for just about all normal apps. But when a full screen game is running the keydown event doesn't fire. Either it is not possible when a full screen game has focus or I don't just know how to do it properly (very likely as I am a newbie in that regards).
Tried using a timer to periodically check for a certain resolution and if 60hz is detected then try to set it to 120hz. The timer does fire and the code tries to change the monitor (which flickers briefly) - but the refresh rate doesn't change.
Another idea I had was to use Mhook or Detours to intercept the 'change display setting'-call. But I don't know if that'll work. And I also have no experience with C++. So I really don't want to go that way if I can avoid it.
Can this be programmatically? I've spent many hours trying to find
something about this online but had no luck.
This settings are not part of the standard .Net Framework but there is interface to manipulate these settings for windows problematically using win32 APIs. you can look here on how to call windows APIs using .Net Framework. then you can call a windows API to change the resolution for instance.

How to monitor different events in 3rd party applications

I am developing a C# application. I am looking for a way to monitor different events in 3rd party applications.
Example 1: Calculator is running, and I want to know when the user has clicked on "=" button.
Example 2: Skype is running and I want to monitor when the user hits the "Call" button.
Example 3: Word is running and I want to monitor when the user opens the "Font" drop down list.
I am not looking for simple Mouse or Keyboard events.
Take a look at EventSpy, Both of those seams to do what you need.
http://www.codeproject.com/Articles/11918/EventSpy
http://eventspy.codeplex.com/
You basically need to tap into the "Windows Messaging" loop. In order to properly filter the GAZILLION messages that come flying through you'll also need to be able to periodically scan through all of the active windows to see which ones (if any) are relevant to you.
Be aware that this whole subsystem of windows is a GIANT security hole. (I have not worked with it much since NT4 / W95/W98 days so they might have tried attempts to "secure" it since then so it might be even harder to get to than it used to be.
You're going to need a good ide / 3rd party tools to help you get started on your way to have some idea of what you're looking for.
In a "previous" life we used this basic technique to get ~4,000 workstations to install their own software, updates, patches, etc through monitoring for existence of certain windows, controls, etc and "injecting" messages into the Windows Messaging loop to control Application Setup Programs, configuration changes that were not stored in the registry, etc, etc...

Detecting raised-event at OS-level (OS Appearance)

I have what seems to be a common problem. I am running Windows 7 Home Premium on one of the most awesomest computers (when it was bought last year) and certain visual effects just automatically turn themselves off.
My average user experience rating is high, so it doesn't explain why this happens. The only feature that ever gets turned off is the 'Show window contents while dragging' option. And it really annoys me.
There are currently no working solutions to this problem online. Other than to "there must be a conflict with another app installed on your machine."
And yes, I do know what app is causing this conflict. It's my bloody Internet Provider's software - you know... that app that you absolutely MUST have open at all times when you're connected to the net.
So, I had a thought. What if I could subscribe to an event so that my app that runs in the background will detect when this 'show window contents while dragging' option is turned off - and then my app will simply turn it back on again.
When I do this manually, it seems to stay in effect for about an hour or two, then it gets switched off again.
Is it possible to handle these types of events, and re-start certain visual effect features? If so, are there any resources on this?
I have not been able to find anything on this sibject yet.
Yes the WM_SETTINGSCHANGE message is sent to all windows when a system setting is changed. Then you can call SystemParametersInfo with SPI_GETDRAGFULLWINDOWS to determine if the "Show window contents while dragging" is disabled and use SPI_SETDRAGFULLWINDOWS to enable it.
So all that you will need to do is create an application with a form (that can even stay hidden) and override the forms WndProc and handle the WM_SETTINGSCHANGE message and call SystemParametersInfo using p/Invoke. The p/Invoke definition for SystemParamtersInfo is available at pinvoke.net
Altough what may be easier is change security on the HKCU\Control Panel\Desktop\DragFullWindows registry value so that it can't be changed.

Running just an app on windows 7

I have to run my C# application that I wrote it recently on several computers with window 7 operating system. Here is a big challenge with it, Application must run on startup and user must not be able to work with anything else such as windows hotkeys, other applications, some directories and etc.
Considering I don’t want to kill any process or service as less as possible, Please give me the best solution.
Thanks and waiting
Maybe A little more information will help
did you see Devices like ATMs or Medical devices that window is running on? Those devices don't allow user to manipulate with desktop or anywhere else, I want their solution. . . my Application Will run as a device handler(A Medical Device in Operating room).
You probably shouldn't write such an application in the first place (nagware?).
Anyway. I think what you are looking for is actually "kiosk" software. Here is blog entry that describes how to lock down the computer to effectively run in "kiosk mode".
Note however, that not every application can (or should) be used in that mode. Either because it has loopholes that still allow you to do thing (for example the file open/save dialog still allows you to create directories or navigate the file system), or because they were simply not designed with that goal in mind.
This sounds actually like a (very) bad idea to me...
You could probably hook every Keyboard event so you disable OS shortcut (Windows + D, Windows + E...). See here.
Also hide the Windows taskbar.
Make sure your application starts with Windows.
This sounds a bit hacky to me...
A program with the properties you mention is called a (very restrictive flavour of) shell. So you need to register your program as a shell (instead of explorer.exe) for the poor, poor user you want to restrict.
You might look into using a local group policy to enforce this restriction. Check this out.

how can I achieve an event without a click or sender or anything?

Say for example if I want to see if ms word is started but I don't want to make a timer ticking every millisecond or if the user doesn't click a button to notify like crazy. Is there some system way to do this? Like ms word starts and it sends some signal to my application? What I am trying to accomplish is actually more sophisticated but the ms word example would suffice... .net or c++/qt/mfc solutions are what I am looking for. 10x!
This article describes a method, using WMI, for receiving an event when processes are added, removed or modified:
http://weblogs.asp.net/whaggard/archive/2006/02/11/438006.aspx
It should be a simple step from this to check if it is MS word or not based on the executable name.
You can use WMI to monitor process creation:
http://weblogs.asp.net/whaggard/archive/2006/02/11/438006.aspx
This may overlap with app starting, but not exactly the same thing.
If you wanted to do something with the app once it started the .net UI Automation could also tell you when windows are created and other such events.
Alternativly, MSAA, Windows Automation, WindowHook are other APIs you might use.

Categories

Resources