How To Check Whether Someone Is Actively Using Their Computer? - c#

I have a program that posts to a database every minute, to show that is running. This is good to make sure that the program is running on a person's computer, but it doesn't tell whether the person is actually actively using their computer (the computer can be locked, or the person might be out of the office, with the program still running and posting to the database).
What is the best way to check if the person is actually actively using the computer?
The first idea that pops into my mind is to create a MessageBox that opens every 5 minutes asking the user to press "OK" if they are present. This would provide the needed functionality, but would annoy the daylights out of anyone using it.
Is there any more behind-the-scenes way to detect whether a person is using their computer? Maybe checking for whether it is locked, or can a WinForm application tell when the mouse and keyboard is being used, even when the WinForm is not the active window?
Any suggestions or help in this matter would be appreciated, thanks!
Addendum: I will assume that if the mouse and keyboard are not being used, a person is not using that particular box (so this would cause a false positive if the user is watching a movie on their computer (this program will be used in an office setting, so the possibility of this happening on a particular day is nearly zero)).

You can set up global hooks for the mouse and keyboard - WH_KEYBOARD_LL and WH_MOUSE_LL - which will allow you to monitor user activity - as long as your user is not, say, watching a film and not touching mouse or keyboard..

The way I'd think about doing it would be to write an application that sits in the background and listens for mouse and keyboard messages using the user32.dll and assumes that the user is no longer using the computer if it doesn't hear any after a certain amount of time. Even then they might be watching a dvd or something though

http://www.ugolog.com/pages/webcam-motion-detection-for-flash-flex-and-csharp
Webcam motion detection + mouse/keyboard hooks = Super Big Brother app.

I think you can do a check using whether screen saver is running or not.
More info : http://bytes.com/topic/c-sharp/answers/261540-detecting-screensaver-state

best way to create some sort of Logging so that it sends usage logs to you. that way you can also analyze what features of the apps have been used actively. Capturing mouse moves and hooks might not make anvivirus on that box happy :)

Related

How to detect whether user is on the desktop C# winforms

I was making a program that changes the desktop background, but there is no need to do this when the user is not on the desktop.
I was wondering if there was a way to detect if the user was on the desktop.
I was also thinking an alternative could be checking whether the user is on any other processes, but I don't know how to do this either.
(I would happily provide my code if necessary)
I'm sorry for posting such a broad question, I hope there is a way to do this though.
Thanks to anyone who can help!
If you want to check application in idle condition then you have to do below:
Add a timer control to your application.
Subscribe to mouseover and keydown events - when they fire, reset the timer.
When the timer fires (ie mouse hasn't moved and key's haven't been pressed for x amount of time), write your logic.
And If want to check idle condition of desktop then below references will be useful for you:
Detecting that the user is away from the PC with .NET
Detecting that the user is away from the PC with .NET
http://www.codeproject.com/KB/cs/ApplicationIdle.aspx
http://msdn.microsoft.com/en-us/library/system.windows.forms.application.idle.aspx
http://ellisweb.net/2008/02/detecting-application-idle-state-in-windows-forms/

How to prevent users from stopping a process in windows? [duplicate]

Long story short, I need to create an application that monitor the sound volume on a computer. The computer's user must not be able to stop the application no matter what.
I'll need to make my app start on computer start up, so the user can't just restart it to enter his session without the application running. As of now I don't know precisely how to do it but with some research this shouldn't be a problem.
My biggest concern is if he just stops the process in the task manager. I guess that I can't avoid that programmatically ? Is there a way to just modify the session's right so that it can't stop processes in the task manager? Or any other solution I didn't think about ?
Or there is no way I can do that and I'll just have to trust my user not to ever stop the program in the task manager ?
Thanks in advance for your help. :)
PS : This will run on a computer in a student club that runs the music for the club and that anyone can access. There are chambers where people sleep the floors above so we don't want people to put the volume too loud. That's it. No malware or anything.
In general, the only programs that act like that are malicious (e.g. rootkits). If you think about it, you really wouldn't want programs to be able to act like that.
As others have indicated, the closest you'll get here is a Windows Service, which automatically starts with Windows. Average users won't know to stop it, but it's still possible to stop it manually for power users.
One work-around you could try is to periodically have it call a web service to verify that it's running. That way you could tell who might have uninstalled or stopped the service. (The problem, of course, is that they might just not have their computer on or something; you could have separate calls for "Start" and "Still On").
Alternatively, if this installed only on computers that are exclusively under your direct control, as others have indicated, you could configure things so that you need administrative access to stop the process. This option was addressed in the comments.
I'm not accusing you of malware - just wanted to illustrate how bad it would be if you could easily make a program that the user can "never stop".
So no you can't make a program that a computer-savvy person could never stop.
But from what I gathered....
Sounds like you want to make it a service. https://msdn.microsoft.com/en-us/library/d56de412(v=vs.110).aspx.
Another (easier I think) option is just to make a console app that starts up from the Task Scheduler http://www.c-sharpcorner.com/uploadfile/manas1/console-application-using-windows-scheduler/.

Prevent users from stopping a process

Long story short, I need to create an application that monitor the sound volume on a computer. The computer's user must not be able to stop the application no matter what.
I'll need to make my app start on computer start up, so the user can't just restart it to enter his session without the application running. As of now I don't know precisely how to do it but with some research this shouldn't be a problem.
My biggest concern is if he just stops the process in the task manager. I guess that I can't avoid that programmatically ? Is there a way to just modify the session's right so that it can't stop processes in the task manager? Or any other solution I didn't think about ?
Or there is no way I can do that and I'll just have to trust my user not to ever stop the program in the task manager ?
Thanks in advance for your help. :)
PS : This will run on a computer in a student club that runs the music for the club and that anyone can access. There are chambers where people sleep the floors above so we don't want people to put the volume too loud. That's it. No malware or anything.
In general, the only programs that act like that are malicious (e.g. rootkits). If you think about it, you really wouldn't want programs to be able to act like that.
As others have indicated, the closest you'll get here is a Windows Service, which automatically starts with Windows. Average users won't know to stop it, but it's still possible to stop it manually for power users.
One work-around you could try is to periodically have it call a web service to verify that it's running. That way you could tell who might have uninstalled or stopped the service. (The problem, of course, is that they might just not have their computer on or something; you could have separate calls for "Start" and "Still On").
Alternatively, if this installed only on computers that are exclusively under your direct control, as others have indicated, you could configure things so that you need administrative access to stop the process. This option was addressed in the comments.
I'm not accusing you of malware - just wanted to illustrate how bad it would be if you could easily make a program that the user can "never stop".
So no you can't make a program that a computer-savvy person could never stop.
But from what I gathered....
Sounds like you want to make it a service. https://msdn.microsoft.com/en-us/library/d56de412(v=vs.110).aspx.
Another (easier I think) option is just to make a console app that starts up from the Task Scheduler http://www.c-sharpcorner.com/uploadfile/manas1/console-application-using-windows-scheduler/.

C# application to use another application in Console

My users must use one application that is made in Console. It is entirely copy and paste, but takes a very long time to finish every procedure.
My team, wanting to save time, created one application that does this with a bot. It does the entire work in more or less 15 minutes, which was around 5 hours before.
The problem is, the user can not use the machine while the bot is running, so even if the user is having less time lost, he keeps loosing time.
So I am wondering, is there a way to create an application which read data from an txt and write into the console (it just need that) in background? Without making the user stop using the machine to do other stuf?
If there is a way, could someone explain how to achieve that?
#EDIT
The user can not use the machine while the bot is working because it is programmed to click automatically in certain parts of the screen (like opening the program) and then write, so if the user move the cursor or write something, everything after will be wrong, so I wanted to create a program which write the things there from background, where the user can use the machine while that happens.
If your bot solution requires control of the mouse pointer and keyboard of the machine to "fake" user input, then there is no way to do what you ask if you think about it. There is only one mouse cursor and keyboard input read by the OS, and if the user should interfere with that by using the machine, while the bot is working i assume it will fail, as the bot probably relies on "move x, move y, click" type of scripting like AutoIT and AutoHotkey does.
However, a workaround i can think of is to set up a virtual machine environment on the actual machine, in which you run the console program and the bot. Then that machine, being virtualized, will have it's own input chain and can be left to it's own while the user uses the host OS at the same time.
This is not very elegant, but it WOULD work. It has some drawbacks:
You would need a license for the virtualized OS
You would need to replicate the toolchain in the virtualized setup
The user must be kept from seeing or interfering with the VM
The VM must be configured to access shared data as needed (shared folders)

how to disable "PRINT SCREEN" button while running my Application in WPF?

How can I disable Print Screen functionality while my WPF application is running?
The use-case is that my client wants to avoid unnecessary replication of valuable patient-centric data from the outside world and they provide the physical security to keep people from taking data through non-digital means.
Okay, it is possible, and could indeed be useful if your application is deployed in an environment where a camera is not available to the user.
First of all, I used the RegisterHotKey and UnregisterHotKey API calls, documented here http://pinvoke.net/default.aspx/user32.RegisterHotKey as described in this rather old article here http://msdn.microsoft.com/en-us/magazine/cc163713.aspx.
I registered the IDHOT_SNAPDESKTOP hotkey in the Window_Load event and unregistered it in the Window_Closed. Trying to do this in the constructor gave me problems getting a consistent handle with the WindowInteropHelper(this) method.
If you'd like to do more than just ignore the keys you can set up a windows message handler, making a kind of WndProc using,
HwndSource source = HwndSource.FromHwnd(<handle>);
source.AddHook(<WndProc>);
making the handle as described above, and the WndProc implementation yourself.
As yet, I don't know how to "not" handle the hot key and get windows to perform its normal behaviour except, of course, by unregistering the hotkeys.
Its not very elegant or "WPF" but it worked for me.
As #ghord comments
The use of EnsureHandle() looks useful for getting a handler in the constructor.
It's not possible to disable printing, and even if it were possible, it would be easily circumvented by a cell phone camera. Many are in the megapixel resolution range, making it quite easy for someone to get the information they want.
If you want to disable the Print Screen Key on your keyboard, Jodrell's answer gives a way of doing that (understanding that it's not going to keep people from printing, and a determined user will find a way around that).
Really, it all comes down to trust. If an employer can't trust their employees not to remove data that is already protected by law in most jurisdictions (HIPAA in the USA), then there's a bigger issue at stake.
Easy:
Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().IsScreenCaptureEnabled = false;
Simply speaking, you cannot. "Print screen" just copies the pixels on the screen to the clipboard, and is not part of your application.
Basically you can hook to the ClipBoard events and then set the image copied to null if someone does it. So they can copy the image but it will be reset:
Have a look at this:
Clipboard event C#
Alternatively in a timer, check the content of the clip board and clear it as soon as it is set to a picture.
No, No way to do that. Even if you capture the Print Screen key in your application user might set focus to some other application and then do the Print screen(having your application on side etc.).
Only way would be to create a dummy application in background which captures all keystrokes using Keyboard Hooks and filters Print Screen, but that will happen for all applications not just yours. And moreover as George said user can use cellphone camera too!
I think Microsoft Rights Management System can help. Give it a try. Following is the link:
Microsoft Rights Management System
The only way I can think of is to use the native Windows API (SetWindowsHookEx) to catch all keystrokes and filter out the PrintScreen key. However this would involve creating a native (i.e. unmanaged) DLL to actually do the keystroke processing.

Categories

Resources