2014-03-27 119 views
1

我需要通过c#安装设备驱动程序(INF文件)。我使用了功能UpdateDriverForPlugAndPlayDevices。但是,它返回我FALSE,但GetLastError()返回一个值,它指示安装的成功消息。 不知道我是否以正确的方式继续进行。 任何人都可以帮忙吗? 由于提前, P以编程方式安装设备驱动程序

回答

1

你应该看看源devcon。它在WDK中可用,正是您所需要的。具体查找devcon will install an INF file的方式。我仍然使用Windows 7 WDK,它位于C:\WinDDK\7600.16385.1\src\setup\devcon

你可能会发现它是using the SetupCopyOEMInf() function,你应该尝试从你的C#应用​​程序中使用它。

+0

它的工作。谢谢:) – Pranoy

+0

代码示例更详细的答案可以在这里找到[如何在安装过程中使用SetupCopyOEMInf](http://stackoverflow.com/questions/18404660/how-to-use-setupcopyoeminf-during-installer) –

1

这个简单的代码为我工作

private void driverInstall() 
    { 

     var process = new Process(); 
     process.StartInfo.UseShellExecute = false; 
     process.StartInfo.CreateNoWindow = true; 
     process.StartInfo.RedirectStandardOutput = true; 
     process.StartInfo.RedirectStandardError = true; 
     process.StartInfo.FileName = "cmd.exe"; 

     process.StartInfo.Arguments = "/c C:\\Windows\\System32\\InfDefaultInstall.exe " + driverPath; // where driverPath is path of .inf file 
     process.Start(); 
     process.WaitForExit(); 
     process.Dispose(); 
     MessageBox.Show(@"ADB/Fastboot/Google Android Driver has been installed"); 
    }