列出所有系统调制解调器
托管代码中有没有办法列出系统上安装的调制解调器/电话设备? 如果.Net没有办法,你能给我指出一个方向吗?
Is there a way in managed code to list the Modem/Telephony devices installed on the system?
If .Net does not have a way, could you point me in a direction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
WMI 将在
Win32_POTSModem
类中包含您需要的所有信息。在 C# 或 .Net 中,您可以利用 System.Management 命名空间来查询 WMI。在 .Net 中,您可以使用 MgmtclassGen.EXE从平台 SDK 生成表示 WMI 类的类对象。
命令行将如下所示:
然后您可以在代码中使用它:
输出如下所示:
您可能还想看看这篇文章: CodeProject:如何:(几乎)通过 C# 实现 WMI 中的所有内容 - 第 3 部分:硬件。。作者围绕 WMI 对象创建了一个简单的类包装器,类似于 MgmtclassGen.exe,但这一切都为您完成了。
WMI will contain all the information you need in the
Win32_POTSModem
class. In C# or .Net, you can utilize theSystem.Management
namespace to query WMI.Within .Net, you can use MgmtclassGen.EXE from the platform SDK to generate a class object representing the WMI class.
The command line would be like this:
and then you can use that in your code:
Output looks like this:
You also might want to take a look at this article: CodeProject: How To: (Almost) Everything In WMI via C# - Part 3: Hardware.. The author has created a simple class wrapper around WMI objects similar to MgmtclassGen.exe, but its all done for you.
只是为后代提供一些想法。
@Christopher_G_Lewis 提供了非常好的解决方案。
但在使用 WMI 之前,我们必须检查
Windows Management Instrumentation
(WMI
,服务名称Winmgmt
)是否正常工作(如何操作?)。当然,微软建议不要碰这个服务,因为它是系统内容的一部分,但人们有时会关闭它。此外,有时检查 WMI 版本 使用前。
如果您想获取当前已连接的调制解调器列表,您可以查看此解决方案。它运行缓慢,但显示所有连接的调制解调器并排除
空调制解调器电缆
。Just some thoughts for future generations.
@Christopher_G_Lewis provided very good solution.
But before using WMI we have to check that
Windows Management Instrumentation
(WMI
, service nameWinmgmt
) is working (how to do it?). Of course, MS recommends don't touch this service, because it's part of system stuff, but people switch it off sometimes.Moreover, sometimes it may be helpful to check WMI version before using it.
If you want to get modems list which are connected at the moment, you can check out this solution. It works slowly, but shows all connected modems and excludes
Null modem cables
.