在 Windows 下以编程方式禁用网络摄像头
如何在 Windows 下以编程方式禁用附加或内置网络摄像头?
通过禁用它们,我的意思是任何尝试访问摄像头的程序都应该:
- 无法访问它们
- 能够访问它们,但它们应该收到黑色图片而不是视频源
我为什么要这样做:
我有带网络摄像头的笔记本电脑。没有简单的方法可以通过软件禁用它。我想创建一个应用程序,其中包含一个禁用网络摄像头的按钮,以便任何想要使用它的应用程序都无法使用它,并创建一个按钮来重新启用它。我不想在摄像头上放置任何东西,否则我不会在这里问这个问题。
How can I disable the attached or built-in webcam(s) programmatically under Windows?
By disabling them, I mean that any program trying to access the cameras should either:
- be unable to access them
- be able to access them, but instead of the video feed, they should receive a black picture
Why I want to do this:
I have a laptop with a webcam. There's no easy way to disable it via software. I want to create an application with a button that disables the webcam, so that any application that wants to use it will be unable to, and a button to re-enable it. I don't want to put anything over the cam physically, otherwise I wouldn't be asking this question here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这里有两个链接,用于以编程方式启用/禁用设备:
我该如何禁用系统设备?
Win32 API 函数以编程方式启用/禁用设备
还有一个官方工具,DevCon,您可以实现自动化。
Here are two links here on SO to enable/disable a device programmatically:
How do I disable a system device?
Win32 API function to programmatically enable/disable device
There is also an official tool, DevCon, that you could automate.
一个简单而有效的解决方案是在后台安装一个应用程序,通过主动捕获来锁定相机(例如以最小分辨率捕获,到
Null Renderer
过滤器,或者可能暂停捕获)甚至更好)。只要您的应用程序获得了对相机的访问权限,其他人就无法从中捕获。另一个解决方案,对于与其他应用程序的交互来说更复杂且有些危险,是重新定义(挂钩、替换)
System Device Enumerator
类并拦截其视频输入设备类别的枚举。掌握了这个,您就可以隐藏相机并且不将其枚举传递给应用程序。这里的关键字是CoTreatAsClass
,这要求您熟悉COM
。这仍然允许旧应用程序通过Video for Windows API
(您可能会同意)访问相机。A simple yet effective solution is to have an application on background which locks the camera by active capture from it (such as capture in minimal resolution, to
Null Renderer
filter, or perhaps paused capture would be even better). As long as your app acquired access to the camera noone else could be capturing from it.Another solution, more complicated and somewhat dangerous as for interaction with other applications, is to redefine (hook, substitute)
System Device Enumerator
class and intercept its enumeration of video input device category. Having hold of this, you can hide the camera and do not pass its enumeration to the application. The keyword here isCoTreatAsClass
and this requires that you are familiar withCOM
. This will still let legacy applications access the camera viaVideo for Windows API
(which you might be OK with).您可以使用 DirectShow 编写一个应用程序来控制网络摄像头,从而阻止其他应用程序访问它。您可能必须使用 C++,并且可能需要 Visual Studio 2005 或更高版本。
首先下载 Windows SDK:http://go.microsoft.com/fwlink/?LinkID= 129787
安装 SDK 后,打开 Visual Studio 并在以下位置打开解决方案:
[SDK Root]\Samples\Multimedia\DirectShow\baseclasses\baseclasses.sln
[SDK Root] 通常为:C:\Program Files\Microsoft SDKs\Windows\v7 .1
构建将创建 strmbase.lib(发布)或 strmbasd.lib(调试)的解决方案。
构建 DirectShow 应用程序需要此库。
接下来打开 AmCap 示例:
[SDK Root]\Samples\multimedia\directshow\capture\amcap\amcap.sln
构建并运行 AmCap。您现在应该能够控制网络摄像头。您可以使用 AmCap 作为您想要执行的操作的基础,甚至可以根据您的需要修改 AmCap。
希望这有帮助。
You can write an application using DirectShow that takes control of the web cam which will prevent other applications from accessing it. You will probably have to use C++ and you will probably need Visual Studio 2005 or greater.
Start by downloading the Windows SDK: http://go.microsoft.com/fwlink/?LinkID=129787
After installing the SDK, open Visual Studio and open the solution at:
[SDK Root]\Samples\Multimedia\DirectShow\baseclasses\baseclasses.sln
[SDK Root] will typically be: C:\Program Files\Microsoft SDKs\Windows\v7.1
Build the solution which will create strmbase.lib (release) or strmbasd.lib (debug).
This library is needed to build a DirectShow application.
Next open the AmCap sample at:
[SDK Root]\Samples\multimedia\directshow\capture\amcap\amcap.sln
Build and run AmCap. You should now be able to control the web cam. You can use AmCap as a basis for what you want to do or you may even be able to just modify AmCap for your needs.
Hope this helps.
阻止用户访问连接到系统的摄像头的唯一方法是卸载其驱动程序。这将是一件极其不友好的事情!
如果您想阻止在应用程序中使用系统设备,那么您所要做的就是从向用户显示的可用设备列表中删除违规设备。
问题:你为什么要这样做?
The only way you can block a user from accessing a camera connected to the system is to uninstall the driver for it. That would be an extremely unfriendly thing to do!!
If you want to block the use of a system device from within your application, then all you have to do is remove the offending device from the list of available devices shown to the user.
Question: Why do you want to do this?
好吧,你不需要为此编程......我相信你知道任务管理器是什么。只需创建一个 .bat 文件(又名 .exe 文件)来终止网络摄像头进程...并使用另一个 .bat 文件来打开它备份?我的意思是这适用于 Windows 上的任何网络摄像头,
但是,如果您想以编程方式执行此操作(这个词对吗?哈哈),那么您必须向我们提供有关网络摄像头类型等的信息……
以防万一您不知道如何制作一个bat文件:
打开一个空的 .txt 文件
输入:
command.com
taskkill /IM notepad.exe
并将文件另存为 everything.bat,并确保更改文件类型(就在您命名文件的位置下方),单击显示“另存为类型:*txt”的位置,然后选择所有文件。
Well you don't need programming for this... I'm sure your aware of what the task manager is. Just create a .bat file (aka the .exe file) that kills the webcam process... and have another .bat file to open it back up? I mean this would work for any webcam on windows,
BUT if you wanted to do it programatically (is that word right? lol) then you'd have to supply us with the information on what type of webcam it is and such...
and just in case you don't know how to make a bat file:
open up an empty .txt file
type in:
command.com
taskkill /IM notepad.exe
and save the file as anything.bat, and be sure to change the file type(right under where you name the file) click on where it says Save as type:*txt, and select all files instead.