2014-03-27 55 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"); 
    }