Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
417 views
in Technique[技术] by (71.8m points)

c# - How to check whether a driver is installed?

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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();
        }
    }
}

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:

Getting all drivers installed on a computer

Get a list of installed drivers | DaniWeb


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...