Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check whether a driver is installed?

Tags:

c#

.net

openvpn

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#?

like image 681
user2430116 Avatar asked Apr 27 '14 19:04

user2430116


1 Answers

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

like image 70
JW Lim Avatar answered Sep 25 '22 10:09

JW Lim