以编程方式安装设备驱动程序
本文关键字:设备驱动程序 安装 方式 编程 | 更新日期: 2023-09-27 17:54:27
我需要通过c#安装一个设备驱动程序(INF文件)。我使用了函数UpdateDriverForPlugAndPlayDevices。但是,它返回me FALSE,但是GetLastError()返回值0,这表示安装成功消息。不确定我是否在以正确的方式进行。有人能帮忙吗?提前感谢,P
您应该查看devcon的源代码。它在WDK中可用,并且正是您所需要的。特别是寻找devcon将安装INF文件的方式。我仍然使用Windows 7 WDK,它位于C:'WinDDK'7600.16385.1'src'setup'devcon
。
你可能会发现它正在使用SetupCopyOEMInf()
函数,你也应该从你的c#应用程序中尝试使用。
这个简单的代码为我工作
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");
}