1

So.. We have a C# utility application for a usb/serial device. I would like to install the driver during the setup process. I know there are lots of posts about this, and I've gone through many msdn and stackoverflow articles, but I just do not seem to succeed.

The driver is OK, it is a stock Arduino driver, so it is signed and can be installed from windows gui (right click on the inf, install) I created a visual studio setup project for our applcation, and a VB project for the custom setup actions. The setup copies the driver to the installation folder. The driver installation is performed from the "OnCommitted" method. Here I spawn a process by calling cmd.exe and would like to call some command to install the driver.

First I tried "RUNDLL32.EXE SETUPAPI.DLL,InstallHinfSection DefaultInstall 132 ", but it is always fails, although I acquire admin rights for this. I tried to acquire admin rights at different places: - I tried to add a "Launch Condition" with the condition "AdminUser" - I tried to run cmd as admin from VB (Process.Startinfo.Verb = "runas") none of the above solved my problem. Then I tried alternative ways to install the driver and InfDefaultInstall.exe is almost fine, but sometimes it fails on some machines, and I don't know why. pnputil.exe always fails for me. I guess the official way to do this is calling InstallHinfSection as MSDN suggests, and I would prefer to use that. We have to support Windows 7 and above.

Any thoughts on what I do wrong? Thanks in advance!

here are my VB methods:

Private Sub InstallDriverPNPUtil()
    Dim infPath As String = """" + Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\arduino.inf" + """"
    Dim processInfo As New ProcessStartInfo("CMD", "/C pnputil -i -a " + infPath)
    processInfo.WindowStyle = ProcessWindowStyle.Hidden
    Dim p As System.Diagnostics.Process = Process.Start(processInfo)
    p.WaitForExit()
End Sub

Private Sub InstallDriverInfDefaultInstall()
    Dim infPath As String = """" + Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\arduino.inf" + """"
    Dim processInfo As New ProcessStartInfo("CMD", "/C InfDefaultInstall.exe " + infPath)
    processInfo.WindowStyle = ProcessWindowStyle.Hidden
    Dim p As System.Diagnostics.Process = Process.Start(processInfo)
    p.WaitForExit()
End Sub

Private Sub InstallDriverInstallHinfSection()
    Dim infPath As String = """" + Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\arduino.inf" + """"
    Dim process As New Process()
    process.StartInfo.FileName = "cmd.exe"
    'fails with and without this
    process.StartInfo.UseShellExecute = True 
    process.StartInfo.Verb = "runas"
    process.StartInfo.Arguments = "/C RUNDLL32.EXE SETUPAPI.DLL,InstallHinfSection DefaultInstall 132 " + infPath
    'MsgBox(process.StartInfo.Arguments, MsgBoxStyle.OkOnly, "InstallHinfSection")
    process.Start()
    process.WaitForExit()
End Sub
blacix
  • 96
  • 8

0 Answers0