windows 检测用户何时截取我的程序的屏幕截图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/774925/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Detect when users take screenshots of my program
提问by Claudiu
I'm writing a Windows application. How can I tell when a screenshot is being taken of it? I read about how to detect the hotkey being pressed, but I'm more worried about the case where every 100 ms or so another program is taking screenshots of it. Namely, I'm trying to notice when someone creates another program (say a python one using ImageGrab, as mentioned in another post) which constantly takes screenshots of my app and uses them to read info off of it.
我正在编写一个 Windows 应用程序。我如何知道何时截取屏幕截图?我阅读了有关如何检测被按下的热键的信息,但我更担心每隔 100 毫秒左右另一个程序对其进行截图的情况。也就是说,我试图注意何时有人创建了另一个程序(比如使用 ImageGrab 的 python 程序,如另一篇文章所述),该程序不断截取我的应用程序的屏幕截图并使用它们从中读取信息。
I don't care much about preventing the screenshots from being taken - I can just ban the user once this behavior is noticed.
我不太关心防止截取屏幕截图 - 一旦注意到这种行为,我就可以禁止用户。
Is this possible? Is there a windows message sent when any app takes a screenshot, like with WM_HOTKEY? Or does windows just use the latest info from the latest paint events, and return that to the other program directly, without my app being able to notice at all?
这可能吗?当任何应用程序截取屏幕截图时,是否会发送 Windows 消息,例如 WM_HOTKEY?还是 Windows 只是使用来自最新绘制事件的最新信息,然后直接将其返回给其他程序,而我的应用程序根本无法注意到?
回答by Greg Hewgill
Whatever you do, people will find a way around it. Suppose such a method existed, where you could reliably detect another program taking a screenshot of your application. To get around that, I could install VirtualBox, run your application inside the VM, and then have a program take screenshots of VirtualBox (which then contains your application). Your application would have absolutely no way to know it was having its picture taken.
无论你做什么,人们都会找到解决方法。假设存在这样一种方法,您可以可靠地检测到另一个对您的应用程序进行屏幕截图的程序。为了解决这个问题,我可以安装 VirtualBox,在 VM 中运行您的应用程序,然后让程序截取 VirtualBox(然后包含您的应用程序)的屏幕截图。您的应用程序绝对无法知道它正在拍摄它的照片。
回答by Nat
This is never going to work. Not only that, but attempts to provide this level of security are going to inconvenience 99% of your legitimate users.
这永远行不通。不仅如此,尝试提供这种级别的安全性会给 99% 的合法用户带来不便。
You perhaps are best to approach the problem from the angle of trying to identify unwanted uses/copies of your information and approach the people/companies using that information.
您可能最好从尝试识别您的信息的不需要的用途/副本的角度来处理问题,并使用该信息来处理人员/公司。
Copyright law is appropriate for this approach, but I understand that there are some intances where this approach is not available.
版权法适用于这种方法,但我知道在某些情况下这种方法不可用。
回答by John Saunders
What if I use a video camera? What if I capture the video coming between the computer and the monitor?
如果我使用摄像机怎么办?如果我捕获计算机和显示器之间的视频怎么办?
I'll be surprised to learn there's any practical way to do this.
我会惊讶地发现有任何实用的方法可以做到这一点。
回答by Reed Copsey
You can (unreliably) do this by using SetWindowsHookEx.
您可以(不可靠地)使用SetWindowsHookEx 来做到这一点。
Here is a complete VB.NET example.
However, there are many ways around this. A hook installed after yours will "override" your hook. Users can take pictures of their screen in many ways, as described in this thread. I'd try to consider other options for protection than this.
然而,有很多方法可以解决这个问题。在您之后安装的钩子将“覆盖”您的钩子。用户可以通过多种方式为其屏幕拍照,如本主题所述。我会尝试考虑除此之外的其他保护选项。
回答by anonymous
First, comments about using a virtual machine are completely pointless -- it is much easier to detect windows running under a virtualizer than to detect a screenshot being taken.
首先,关于使用虚拟机的评论完全没有意义——检测在虚拟机下运行的窗口比检测正在截取的屏幕截图容易得多。
A good way to make screenshots difficult would be to rewrite your program to run in full screen mode under some ancestral dos extender.
使屏幕截图变得困难的一个好方法是重写您的程序,使其在某些祖先的 dos 扩展程序下以全屏模式运行。
A good way to ban 95% of users who ever attempted to take a screenshot is to display a huge flashing banner on startup ("screenshots prohibited! you be banned!"), and detect user pressing PrtScrn during the following 15 seconds.
禁止 95% 曾尝试截屏的用户的一个好方法是在启动时显示一个巨大的闪烁横幅(“禁止截屏!你被禁止!”),并在接下来的 15 秒内检测用户按下 PrtScrn。
回答by Arjan
Another reason why I think it will be impossible to achieve this:
我认为不可能实现这一目标的另一个原因:
A long time ago, I failed to make a screen capture of the content of Windows Media Player, because (I assumed) WMP streamed that content to the videocard right away. (Fun detail: after pasting the screen capture, the video would continue playing in MS Paint, but saving the image would eventually yield a black square). Anyway, using VNC made it very easy to get the screen capture after all.
很久以前,我未能对 Windows Media Player 的内容进行屏幕截图,因为(我假设)WMP 立即将该内容流式传输到视频卡。(有趣的细节:粘贴屏幕截图后,视频将继续在 MS Paint 中播放,但保存图像最终会产生一个黑色方块)。无论如何,毕竟使用 VNC 使获取屏幕截图变得非常容易。
回答by Mun
It's pretty hard to stop it completely... A user who is determined enough could just take a photo of the screen with a digital camera.
很难完全阻止它......一个有足够决心的用户可以用数码相机拍摄屏幕照片。
回答by Chris Doggett
The way I usually take screenshots (from C#) is by calling BitBlt, which is the basis of a lot of screen painting. Not sure how you'd intercept calls to it in any meaningful way, since probably every program on the system uses it at a low level.
我通常截图的方式(来自C#)是通过调用BitBlt,这是很多屏幕绘制的基础。不确定您将如何以任何有意义的方式拦截对它的调用,因为系统上的每个程序可能都在低级别使用它。
回答by Liran Orevi
I assume you really can't because one can always run your program in a window with virtual machine, then using a capture program on the outside platform, and knowing if this is happaning is mighty difficult. I suggest thinking more in ways of special rendering pace or interlacing, special contrasts, etc...
我认为你真的不能,因为人们总是可以在带有虚拟机的窗口中运行你的程序,然后在外部平台上使用捕获程序,并且知道这是否发生是非常困难的。我建议更多地考虑特殊的渲染速度或隔行扫描、特殊对比度等......
You can also run your outputs to the screen as if it was a movie, encode it with a low rate and resolution encoder, so that a still capture every 100ms will be in such a low quality that it would be worthless. (have you ever freezed a low quality movie?)
您还可以将输出运行到屏幕上,就好像它是一部电影一样,使用低速率和分辨率的编码器对其进行编码,这样每 100 毫秒的静态捕获质量就会很低,以至于毫无价值。(你有没有冻结过低质量的电影?)
however you really should consider using other ways to protect your info.
但是,您确实应该考虑使用其他方式来保护您的信息。
回答by SarmenHB
there is one way that i think might stop it. learn about the technology that blurs a graphical display when it is duplicated for example.
我认为有一种方法可以阻止它。例如,了解在复制图形时模糊图形显示的技术。
screenshot, photographed by digital camera screenshot from virtual os.
截图,数码相机截图来自虚拟操作系统。
play with it , who knows you might invent something that will make u millions.
玩玩它,谁知道你可能会发明一些能让你赚到数百万的东西。