【问题标题】:Installing a device driver programmatically以编程方式安装设备驱动程序
【发布时间】:2014-03-27 09:20:57
【问题描述】:

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

【问题讨论】:

    标签: c# installation device-driver inf getlasterror


    【解决方案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# 应用程序中使用它。

    【讨论】:

    【解决方案2】:

    这个简单的代码对我有用

        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");
        }
    

    【讨论】:

    • 在没有用户登录的情况下可以使用吗?它是否适用于没有本地管理员权限的用户?
    猜你喜欢
    • 2017-07-18
    • 1970-01-01
    • 2014-04-06
    • 2012-05-05
    • 2013-11-15
    • 2011-01-18
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    相关资源
    最近更新 更多