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

8

8

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.

Overburdensome answered 8/10, 2010 at 10:57 Comment(6)
yes george your correct there camera available in the market. But at certain case my client wants to avoid unnecessary replica of the valuable Patient centric data outside and they are ready to provide the security.Overburdensome
but any screen capture program could save the screen data without the print-screen button. or program installations are blocked?Blueprint
The pixels in the video adapter are accessible by any program. Securing the data and the machine is your customer's problem. They can buy custom keyboards with the button missing, if that's their concern. It is a silly one, they are only pixels, not data.Summertree
The request reminds me of those "no right click" Javascripts on the web, those that try to prevent you from copying an image off a page. You can't hide data from a computer if you still intend to show it to a person looking at the screen.Therewith
The point here (I got the same problem) is to provide the best effort solution. We all know there are ways to steal a car and a good thief will be able to steal your car, but by locking the door, you will prevent petty ones from doing it...Rie
Related: How do I make it more difficult for somebody to take a screenshot of my window?Pontias
T
4

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.

Topsail answered 8/10, 2010 at 10:58 Comment(0)
N
5

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.

Neighborhood answered 14/3, 2011 at 17:23 Comment(1)
If you have problems getting Handle, remember to use EnsureHandle() method.Tormoria
T
4

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.

Topsail answered 8/10, 2010 at 10:58 Comment(0)
G
2

Easy:

Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().IsScreenCaptureEnabled = false;
Gimcrackery answered 2/5, 2017 at 9:24 Comment(1)
Helpfull, but it is for Win RT onlyPhira
T
0

Simply speaking, you cannot. "Print screen" just copies the pixels on the screen to the clipboard, and is not part of your application.

Therewith answered 8/10, 2010 at 11:3 Comment(2)
is there anyway to detect whether print screen button clicked from my app?Overburdensome
Not reliably. Furthermore, as your later comment indicated, this would be a "security" mechanism. That is to say, the people pressing it will try to find ways around your protection. Starting out with something this unreliable just invites them to break the protection entirely.Therewith
O
0

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.

Ozzie answered 8/10, 2010 at 11:17 Comment(0)
A
0

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.

Acquiescent answered 8/10, 2010 at 11:42 Comment(2)
But this can be defeated by a screenshot program that directly writes to file.Vincent
It can be defeated by much lower tech stuff anyway! The point was to disable the PrintScreen button which my solution does it although not directly.Acquiescent
G
0

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!

Glutinous answered 8/10, 2010 at 11:44 Comment(0)
B
0

I think Microsoft Rights Management System can help. Give it a try. Following is the link:

Microsoft Rights Management System

Brigand answered 8/10, 2010 at 11:50 Comment(1)
Nope. Unrelated server-side technology.Therewith

© 2022 - 2024 — McMap. All rights reserved.