3

Is there a way to prevent or disable video capturing of my WPF application? Probably some Win32 API calls or some mask over my WPF content. Or if it is imposible is there a way to at least prevent the most popular screen capture programs from recording what is happening in my WPF application?

Nikolay Kostov
  • 14,580
  • 20
  • 75
  • 115
  • what kind of application is that... – Federico Berasategui Jan 05 '15 at 13:55
  • perhaps with an api that can shut down the monitor... X) – JYL Jan 05 '15 at 13:57
  • @HighCore, it's a test system in WPF that runs chrome browser inside and I don't want the questions to be exposed in any kind of way. I've already secured the connection, the selection of the text, disabled a lot of keys (alt-tab, win key, etc.) and the next thing I want to do is to disable screen capturing. :) – Nikolay Kostov Jan 05 '15 at 14:02
  • @NikolayKostov there must be a way to achieve what you need. Unfortunately I don't know how to do it, but I've seen other Windows apps do that so it must be possible somehow ;) Good Luck. – Federico Berasategui Jan 05 '15 at 14:09

1 Answers1

6

To prevent an application from capturing window contents, you can call the SetWindowDisplayAffinity Windows API with a WDA_MONITOR affinity. While this prevents applications from capturing a screen, it will not prevent a user from whipping out their smart phone and taking a picture of the screen.

The API is available on systems running Windows 7 and later. It's also required that Desktop Window Manager composition is enabled. Turning off DWM composition will undo the effect, so you need to prevent users from turning DWM composition off. If you are running Windows 8 and later, this is not an issue, since Desktop Window Manager is always on.

IInspectable
  • 35,521
  • 8
  • 69
  • 148
  • My code is: ```NativeMethods.DwmEnableComposition(CompositionAction.DwmEcEnablecomposition); NativeMethods.SetWindowDisplayAffinity( Process.GetCurrentProcess().MainWindowHandle, DisplayAffinity.Monitor);``` But Camtasia is still recording my windows. Am I missing something? – Nikolay Kostov Jan 05 '15 at 15:00
  • 1
    @Nikolay: Camtasia may be sending [WM_PRINT](http://msdn.microsoft.com/en-us/library/windows/desktop/dd145216.aspx) or [WM_PRINTCLIENT](http://msdn.microsoft.com/en-us/library/windows/desktop/dd145216.aspx) messages to your window, and thereby bypass the protection. Try using the regular PrntScr button to see if this works as desired, and deal with specific tools later. – IInspectable Jan 05 '15 at 15:06
  • 2
    @Nikolay: In that case you are probably using the wrong window handle. `MainWindowHandle` cannot work, since a process can have any number of toplevel windows. I would recommend setting a [CBT Hook](http://msdn.microsoft.com/en-us/library/windows/desktop/ms644977.aspx) on your GUI thread, and set the affinity in your `HCBT_CREATEWND` handler. This has two advantages: It will set the affinity for any window, regardless how it's created, and it won't leave a window of opportunity for an attacker. – IInspectable Jan 05 '15 at 15:38
  • @IInspectable , calling `SetWindowDisplayAffinity` my application's top windows works perfectly. I can see black screen after PrntScr, but as Nikolay mentioned some applications still captures the screen/window like Camtasia, Any Desk etc. I read your above comment mentioning about WM_PRINT etc. so How I can deal with such specific tools? – Amogh May 22 '19 at 12:20
  • @amo: In short: You cannot. This is an arms race, and all you can hope for is making it harder for an attacker. It will always be possible to get to the data in an open system. If you need that sort of protection, you would have to run your application on a system, that better isolates applications (like [Windows 10 in S mode](https://support.microsoft.com/en-us/help/4020089/windows-10-in-s-mode-faq)). – IInspectable May 24 '19 at 12:39
  • @IInspectable, thanks for your reply. DO you have any idea how VLC player's "directx video output" works? In that output mode the video playing in VLC is black on almost all of the screen capturing applications as well as on remote software like TeamViewer, AnyDesk etc. – Amogh May 24 '19 at 13:10
  • @amo: The name of the renderer suggests, that it is using DirectX for rendering. DirectX (and OpenGL) output is generally harder to intercept. If you need to know for sure, you'll have to dig through the code. VLC is [open source](https://www.videolan.org/vlc/download-sources.html). – IInspectable May 24 '19 at 13:24
  • @IInspectable I am already started with it from today morning but still didn't find lead. And one question is still in head is whatever VLC is doing is on video content I want to hide my c# winform from remote taking apps..`SetWindowDisplayAffinity` works but not with every remote taking apps – Amogh May 24 '19 at 13:29
  • @IInspectable Even yesterday I tried creating "secure desktop" using `CreateDesktop` win32 API n launched a c# winform and checked on some remote taking apps but still some of them shows original desktop n some others shows virtual desktop. So that solution is also not full proof the requirement. – Amogh May 24 '19 at 13:38
  • @IInspectable can you help with this https://stackoverflow.com/questions/56302217/prevent-desktop-sharing-of-a-particular-c-sharp-winforms-or-detect-desktop-shari – Amogh May 25 '19 at 06:10