Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i prevent screen recording using C#

Tags:

c#

I display a video in a media player after I decrypt it, and I want to make it save across and prevent print screen and screen recording by any program.

like image 698
nada diaa Avatar asked Feb 20 '17 18:02

nada diaa


People also ask

Can screen recording be prevented?

Screen Capture protection is possible in Android App, IOS App or IOs browser, but desktop and android browsers can not prevent screen capture.

How do I stop screen recording permission?

but if you want to restart the permissions Go to Application Manager -> App Permissions -> Requested Permission -> turn it off / on for your program .


1 Answers

Office 2013 and later tries to prevent screenshots of Office application windows if they have an IRM-document currently open. When you take a screenshot you get a black rectangle instead of the window contents.

I asked a similar question a few years ago. You can prevent screenshots of your application window by using SetwindowDisplayAffinity: How does Office 2013 implement black windows for IRM?

HWND myWindowWindowHandle = ...
BOOL ok = SetWindowDisplayAffinity( myWindowWindowHandle, WDA_MONITOR );
if( !ok ) exit(1);
ShowWindow( myWindowWindowHandle, SW_NORMAL );

This requires Windows 7 or later, and the system must be running with the DWM enabled (the DWM always runs on Windows 8 or later).

Raymond Chen also blogged about it here: https://blogs.msdn.microsoft.com/oldnewthing/20130603-00/?p=4193

In the old days (before the DWM in Windows) video was often displayed using the Video Overlay feature in graphics cards, where compressed video would be fed into the GPU and decoded and never sent back into system RAM (instead a special color was used to define pixels on screen where the video would be overlayed: https://en.wikipedia.org/wiki/Video_overlay, so that's why previously screenshots could not be taken of video: it wasn't DRM, just a side-effect of a performance optimization)

Note that it is mathematically impossible for DRM to work perfectly (in the Alice and Bob analogy, Bob (the intended recipient) and Charlie (someone trying to intercept the content) are the same person), so be wary of investing too much time into this.

Note that SetWindowDisplayAffinity does not stop all screen-recording tools, for example recent GPUs have built-in support for hardware-accelerated display output capture (I believe this is what the Windows Game DVR uses) which might not be affected by WDA_MONITOR. Users could also run your software in a virtual-machine environment, or modify Windows to disable the DWM (trivial on Windows 7, difficult but still possible on Windows 8 and 10).

UPDATE:

There's a comment in Raymond Chen's blog which cautions that another process (with a hWnd of another process' window) could simply call SetWindowDisplayAffinity( otherProcessesWindowHandle, WDA_NONE ); to remove DisplayAffinity protection. I don't know if it would work or not, I'd like to ask you to try it and let us know if another process can defeat it that way.

like image 73
Dai Avatar answered Nov 15 '22 07:11

Dai