本文介绍了如何检查是否安装了驱动程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个VPN项目..我有一个关于 TUN / TAP 一个小疑问。

I am working on a VPN project.. I have a small doubt regarding TUN/TAP.

我如何以编程方式检查/如果TUN / TAP驱动程序是用C#在系统上安装检测?

How do I programmatically check/detect if a TUN/TAP driver is installed on a system in C#?

推荐答案

您可以检查是否有特定的驱动程序被执行的。

You can check if a particular driver is installed by executing a WQL SelectQuery.

using System;
using System.Management;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Searching for driver...");

            System.Management.SelectQuery query = new System.Management.SelectQuery("Win32_SystemDriver");
            query.Condition = "Name = 'SomeDriverName'";
            System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(query);
            var drivers = searcher.Get();

            if (drivers.Count > 0) Console.WriteLine("Driver exists.");
            else Console.WriteLine("Driver could not be found.");

            Console.ReadLine();
        }
    }
}

如果上面的code编译失败,一定要添加引用 System.Management 组件。

If the above code fails to compile, make sure you add a reference to the System.Management assembly.

您还可能会发现这些参考资料很有帮助:

You may also find these references helpful:

获取计算机上安装的所有驱动程序

<一个href="http://www.daniweb.com/software-development/csharp/$c$c/217155/get-a-list-of-installed-drivers">Get安装驱动程序的列表| DaniWeb

这篇关于如何检查是否安装了驱动程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 11:53