托管代码中是否有一种方法可以列出系统上安装的调制解调器/电话设备? 如果.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?
最满意答案
WMI将包含Win32_POTSModem类中所需的所有信息。 在C#或.Net中,您可以使用System.Management命名空间来查询WMI。
在.Net中,您可以使用平台SDK中的MgmtclassGen.EXE生成表示WMI类的类对象。
命令行将是这样的:
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\mgmtclassgen.exe Win32_POTSModem /L CS /P c:\POTSModem\Win32_POTSModem.cs然后你可以在你的代码中使用它:
using System; using System.Collections.Generic; using System.Management; using ROOT.CIMV2.Win32; public class MyClass { public static void Main() { foreach (POTSModem modem in POTSModem.GetInstances()) { Console.WriteLine(modem.Description); } } }输出看起来像这样:
ThinkPad Modem - Internal Modem Speed: 56000您还可以查看本文: CodeProject:如何:(几乎)通过C#在WMI中的所有内容 - 第3部分:硬件。 。 作者创建了一个类似于MgmtclassGen.exe的WMI对象的简单类包装器,但它们都是为你完成的。
WMI will contain all the information you need in the Win32_POTSModem class. In C# or .Net, you can utilize the System.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:
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\mgmtclassgen.exe Win32_POTSModem /L CS /P c:\POTSModem\Win32_POTSModem.csand then you can use that in your code:
using System; using System.Collections.Generic; using System.Management; using ROOT.CIMV2.Win32; public class MyClass { public static void Main() { foreach (POTSModem modem in POTSModem.GetInstances()) { Console.WriteLine(modem.Description); } } }Output looks like this:
ThinkPad Modem - Internal Modem Speed: 56000You 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.
更多推荐
发布评论