以编程方式安装设备驱动程序

时间:2014-03-27 09:20:58

标签: c# installation device-driver inf getlasterror

我需要通过c#安装设备驱动程序(INF文件)。我使用了函数 UpdateDriverForPlugAndPlayDevices 。但是,它返回 FALSE ,但GetLastError()返回值 0 ,表示安装的成功消息。 不确定我是否以正确的方式进行。 有人可以帮忙吗? 提前致谢, P

2 个答案:

答案 0 :(得分: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#应用程序中使用它。

答案 1 :(得分: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");
    }
相关问题