views:

631

answers:

3

I would like to deploy a .inf based USB driver with my installer.

I guess the .inf needs to be placed in %SystemRoot%\inf, but there is also a .cat (WHQL certification I guess?), and .sys files. What do I do with those?

EDIT: Resolved, thanks to the helpful answers. I was able to P/Invoke the function, so I have a post-install action which runs the following code:

namespace DriverPackageInstallAction
{
    static class Program
    {
        [DllImport("DIFXApi.dll", CharSet = CharSet.Unicode)]
        public static extern Int32 DriverPackagePreinstall(string DriverPackageInfPath, Int32 Flags);

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            DirectoryInfo assemblyDir = new DirectoryInfo(Application.ExecutablePath);
            DirectoryInfo installDir = assemblyDir.Parent;

            int result = DriverPackagePreinstall(installDir.FullName + @"\Driver\XYZ.inf", 0);
            if (result != 0)
                MessageBox.Show("Driver installation failed.");
        }
    }
}
A: 

You could try asking the shell to install it for you:

%SystemRoot%\System32\rundll32.exe setupapi,InstallHinfSection DefaultInstall 132 YOUR_FILE.inf

But I'm 100% sure there's a better way...

scraimer
This does not work
Christopher
Well, it worked on my computer when I tried it... I guess your computer is just different...
scraimer
+3  A: 

I would start by reading about SetupAPI and DIFx. The Windows Driver Kit includes samples of both, including a DIFx-based merge module and a DIFx-based WiX library. The source for the command-line devcon utility, which is based on SetupAPI, is also included in the WDK samples.

bk1e
correct links: http://msdn.microsoft.com/en-us/library/ff550855.aspx and http://msdn.microsoft.com/en-us/library/ff544838.aspx
Dercsár
@Dercsár: thanks, I'll update all 4 links to point to the new locations.
bk1e
A: 

Sorry for the misleading, this is actually a comment goes to scraimer.

It will work only if your inf has a [DefaultInstall] section.

Also, if the driver is not signed, this method won't work if your device is not connected.

AZ
Thanks, nice to know! How did yoy find out about the "not signed" + "not connected" combination? Is there some documentation from Microsoft about this?
scraimer

related questions