Link to home
Start Free TrialLog in
Avatar of deer22
deer22Flag for United States of America

asked on

Automatic driver search install using an inf file - FTDI

I have a device that uses FTDI's FT245B chip.  They provide the drivers for this chip.  I have a vb.net (vs2005) windows application that the user uses to access my device over USB.  The problem I am having is the user has to install the drivers first and the way it is now they have to find the drivers by browsing to them to where they installed the program at before windows Find New Hardware wizard can install the drivers.  This is a problem for most users.  

My question is how do I install this inf file so windows knows where the driver is located so the user can just click to search automatically?
Do I need to make a change to the INF file?
Is there some code in vb.net I can do this with?

The drivers can be found here:
http://www.ftdichip.com/Drivers/D2XX.htm
version 2.06.02

Thanks for the help!
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

ASKER CERTIFIED SOLUTION
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of deer22

ASKER

Thanks sedqwick I got it working now and works fine with the warnings of course since the drivers are not signed.  I tested it with XP and Windows 7.  Windows 7 didn't even make me use the FNHW, it just installed them automatically when I connected the device.  I still had to use the FNHW on XP, but didn't have to manually locate the drivers like I use to.  Great to know...Heck FTDI themselves didn't even know how to do it...lol...Anyways, I am posting some code below that should help save developers a lot of time...this code is in VB.net and was written using visual studio 2005...

Note: Drivers are NOT added to Add?Remove Programs in Control Panel and I haven't tried uninstalling them...just manually so far...we'll leave that for another day...

Imports System.Runtime.InteropServices

Imports System.Runtime.InteropServices.Marshal

Const DRIVER_PACKAGE_REPAIR As Int32 = &H1

Const DRIVER_PACKAGE_SILENT As Int32 = &H2

Const DRIVER_PACKAGE_FORCE As Int32 = &H4

Const DRIVER_PACKAGE_ONLY_IF_DEVICE_PRESENT As Int32 = &H8

Const DRIVER_PACKAGE_LEGACY_MODE As Int32 = &H10

Const DRIVER_PACKAGE_DELETE_FILES As Int32 = &H20

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _

Public Structure INSTALLERINFO

Public pApplicationId As String

Public pDisplayName As String

Public pProductName As String

Public pMfgName As String

End Structure

'This will pre install the inf file (UNSIGNED) into the Driver store

'Location Example - C:\WINDOWS\system32\DRVSTORE

'Has been tested on XP and Windows 7, should work on any version after Win2000

'

'##############################################################################

'Note: if the device is connected before running code below the drivers will

'be installed without using Found New Hardware Wizard. If the device is not

'connected then FNHW is used on XP. On Windows 7 the drivers are installed

'without the FNHW as soon as the device is connected.

'

'location of the inf file

Dim infFile As String = SourceINFFILE

'DRIVER_PACKAGE_LEGACY_MODE - obsolete on Vista and later, however,

'it still works with unsigned drivers on these systems

'DRIVER_PACKAGE_REPAIR - forces installation, otherwise, if already pre-installed

'causes an error.

Dim Flags As Int32 = DRIVER_PACKAGE_LEGACY_MODE Or DRIVER_PACKAGE_REPAIR

'reboot after install

Dim fNeedReboot As Boolean = False

'Structure relates driver package with an application

Dim installerInfo As INSTALLERINFO = New INSTALLERINFO()

installerInfo.pApplicationId = vbEmpty 'GUID

installerInfo.pDisplayName = vbEmpty

installerInfo.pProductName = vbEmpty

installerInfo.pMfgName = vbEmpty

Dim ptrInstallerInfo As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(installerInfo))

Marshal.StructureToPtr(installerInfo, ptrInstallerInfo, False)

Dim InstallResult As Int32 = DriverPackageInstall(infFile, Flags, ptrInstallerInfo, fNeedReboot)

Marshal.FreeHGlobal(ptrInstallerInfo)