You are currently viewing Install a .inf driver programmatically using C# .Net
Install a .inf driver programmatically using C# .Net

Install a .inf driver programmatically using C# .Net

Here is the example to Install a .inf driver programmatically using C# .Net.

Installation of .inf driver using c# is easy. Please check the following code for that.

private static void driverInstall(string driverPath)
       {

           try
           {
               var process = new Process();
               process.StartInfo.UseShellExecute = false;
               process.StartInfo.CreateNoWindow = true;
               process.StartInfo.RedirectStandardOutput = true;
               process.StartInfo.RedirectStandardError = true;
               process.StartInfo.FileName = "C:\\Windows\\System32\\cmd.exe";
               string a = @"" + driverPath + "";
               process.StartInfo.Arguments = "/c C:\\Windows\\Sysnative\\PnPutil.exe -a \"" + driverPath + "\""; // where driverPath is path of .inf file
               process.Start();
               process.WaitForExit();
               process.Dispose();
               Console.WriteLine(@"Driver has been installed");
           }
           catch (Exception ex)
           {
               Console.WriteLine(ex.Message);
           }
       }

Note: Please note that here I used Windows\Sysnative folder instead of Windows\system32 for PnPUtil.exe path. c:\windows\system32\pnputil.exe path is ok for 32bit system. But when you are working with a 64bit system, you must change path to c:\windows\sysnative\pnputil.exe.

You may face the following error during .inf driver installation using c#.

Error: pnputil.exe is not recognized as an internal or external command, operable program or batch file.

Solution:

If you are using path “c:\windows\system32\PnPUtil.exe” for cmd arguments then you may face the error like “pnputil.exe is not recognized as an internal or external command, operable program or batch file”. The Solution is simple replace “c:\windows\system32\PnPUtil.exe” with  “c:\windows\sysnative\pnputil.exe” as per my above example. for more details you can visit: https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z0000019L4VSAU&l=en-IN