- Whenever repackaging a driver application the first step is to figure out the type of driver by analyzing the source for driver files and registries.
- The driver may be a printer driver, a signed or unsigned driver, driver setup available with the source (MSI or EXE or Command line setup), installation information (.inf) file available with the driver, driver getting implemented via registries(This refers to mainly a system driver with .sys extension which creates and starts the corresponding service related to its function) .
- If you can not find ".exe" or ".msi" from source then try to search for driver on Internet by name of company or name of driver for e.g. Broadcom NetXtreme Gigabit Ethernet Driver.
- If you can not find Driver setup from Internet. Then again look for the driver related files (.INF, .Sys, .cat, .dll) in initial capture. If original application setup is implementing the driver using the ".INF, .sys, and .Cat" then most of the time you will get these files installed by application under “application folder\Driver" or Under "Windows\System32\Drivers" folder.
- Many, if not all, printer settings can be done from Windows 2000's/Windows XP command line using PRINTUI.DLL and RUNDLL32.EXE.
- The list of functions on this page was generated using the following command in Windows XP (Professional):
RUNDLL32 PRINTUI.DLL, PrintUIEntry [options] [@commandfile]
RUNDLL32 PRINTUI.DLL, PrintUIEntry /il /c\\machine
RUNDLL32 PRINTUI.DLL, PrintUIEntry /o /n\\machine\printer
RUNDLL32 PRINTUI.DLL, PrintUIEntry /if /b "Test Printer" /f %windir%\inf\ntprint.inf /r "lpt1:" /m "AGFA-AccuSet v52.3"
- 1.The rundll32.exe process is responsible for running DLLs and placing its libraries in the memory. The rundll32.exe process is known as a command line utility program, and it performs its embedded functions along with the rundll.exe file. Rundll32.exe works by invoking a function that is exported from a specific 16-bit or 32-bit DLL module. However the only DLLs that you can call with the rundll.exe and rundll32.exe files are the ones that are only specified to be accessed by these processes.
- The rundll32.exe file operates by parsing the command line. The specified DLL is then loaded through the function LoadLibrary (). Afterwards, from the function, it gets the addresses through GetProcAddress (). The command line tail is passed when it is called. Next, the DLL is unloaded upon the return of. Finally, the rundll32.exe file exits. The following command can be used for driver implementation using the driver's standard .Inf file:
"%SystemRoot%\System32\rundll32.exe setupapi, InstallHinfSection <SectionName> 132 %1"
ParameterExplanation<SectionName>This is to be decided as per each driver and will refer to its installation section within the .INF file"%1"This parameter refers to the full path of the installation .Inf file
Method3Implementation Using .SYS files(Implementation via hardware registries)[ALREADY POSTED IN PREVIOUS POST]
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\<drivername>\*HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\<drivername>\Security\*HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\<drivername>\Parameters\*<drivername> in many cases will be the .sys file name.Include these registries in the MSI. System needs reboot after installing the MSI. After reboot these drivers will get configured by themselves.Example: To implement VPN-1 SecureClient Adapter, the registries that are included in the package are shown below:As per as my experience of repackaging a .sys files involved a custom action to run in system context to start the corresponding service offered by the driver file as:Create and start a service that runs the .sys driversc create npf binPath= system32\drivers\<filename>.sys type= kernel start= auto error= normal tag= no DisplayName= "<DisplayName>"Method4Implementation using command line from source EXE or MSI
- Some drivers are unsigned and do not have any .inf file for installation. In this case the drivers are implemented through .sys files.
- These drivers can be seen in Device Manager by clicking show hidden drivers.
- Most of the times one can see the hidden drivers under non plug and play drivers tab
- To implement these drivers within the MSI, use the registry values under
- Check the source whether driver related exe is present or not. Most of the time you will find driver related ".exe" or ".msi" in the one of the source folder.
- If you find such ".exe" or ".msi" then use the same file to implement Driver in your MSI Package. Write a Custom Action "Execute program from Installation" in Deferred Execution/Immediate execution with silent (-s, /quite, /silent etc.) option.
3. Most of the time you can find the command line getting written at C:\Windows\setupapi.log file.Method5Implementation using Setupapi.dll1. Certain driver related applications when installed have information like PNF, INF, CAT file at location “C:\Windows\inf”.As per the driver, this are by default name to oemXX.pnf or oemXX.inf where XX stands for the number .E.g. oem1.INF, oem1.PNF and so on. As a result whenever a driver application is repackaged containing this information, the XX value is hardcoded and it does affect other driver information files which are already present on the target machine.2. To overcome the above issue we write certain custom actions using the file ‘setupapi.dll’ in such a way that it checks for the maximum XX value present on the machine and accordingly installs the PNF or INF file of the repackaged application.
· SetupAddToSourceList Function1. The SetupAddToSourceList function appends a value to the list of installation sources for either the current user or the system. If the value already exists, it is removed first, so that duplicate entries are not created.2. A caller of this function is required to have administrative privileges, otherwise the function fails.3. Unicode Implemented as SetupAddToSourceListW (Unicode) and SetupAddToSourceListA (ANSI).4. In our DB environment we use ANSI format hence our Function name will be SetupAddToSourceListA· SetupCopyOEMInf function1. The SetupCopyOEMInf function copies a specified .inf file into the %windir%\Inf directory. SetupCopyOEMInf does not recopy the file if it finds that a binary image of the specified .inf file already exists in the INF directory with the same name or a name of the form OEM*.inf. When SetupCopyOEMInf copies a file, it renames the copied file to OEM*.inf. Name provided is unique and cannot be predicted.2. SetupCopyOEMInf uses the following procedure to determine if the .inf file already exists in the Inf directory:3. All .inf files with names of the form OEM*.inf are enumerated and any files that have the same file size as the specified .inf file are binary compared.4. The Inf directory is searched for the source filename of the .inf file. If an .inf file of the same name exists and is the same size as that of the specified .inf file, the two files are binary compared to determine if they are identical.5. If the specified .inf file already exists a further check is performed to determine if the specified .inf file contains a CatalogFile= entry in its [Version] section. If it does, the .inf file’s %windir%\Inf primary filename with a ".cat" extension is used to determine if the catalog is already installed. If there is a catalog installed, but it is not the same as the catalog associated with the source .inf, this is not considered to be a match and enumerations continue. It is possible to have multiple identical .inf files with unique catalogs contained in %windir%\Inf directory. If an existing match is not found, the .inf and .cat files are installed under a new and unique name.6. OEM .inf files that do not specify a CatalogFile= entry are considered invalid with respect to digital signature verification.7. In cases where the .inf file must be copied to the %windir%\Inf directory, any digital signature verification failures are reported.8. If the .inf and .cat files already exist, these existing filenames are used and the file replacement behavior is based on the specified CopyStyle flags. Replacement behavior refers only to the source media information stored in the .pnf. Existing .inf, .pnf, and .cat files are not modified.SAMPLE MSI HAVING CUSTOM-ACTIONS
- This method is time consuming as it requires creating multiple custom actions for copying oem/pnf files. In the next method will discuss "DPInst.exe" related to driver based packages.
- Setupapi.log located at C:\Wnidows records the driver’s related specifications. The following are some important functions as part of the Setup API.
- Create a folder and install the driver files to this folder. This folder can be in INSTALLDIR too.
- In the Execute Deferred section sequence an If Statement custom action after the InstallFiles action. Make the execution of this action only apply on install by giving it the condition "NOT Installed"
1. Custom Action Name: SETUPADDTOSOURCELISTA2. DLL File: [SystemFolder]setupapi.dll3. Function Name: SetupAddToSourceListA4. Parameter: dword, Constant, 000001005. Parameter: string pointer, Constant, <Path to driver.inf file>. (Don't enclose paths in double quotes)6. Return Value Type: dword7. Return Property: DLLRETURN (Pre creating a property has more consistent results)· Add a second "Call Custom DLL From Destination" custom action within the same If\End statement with the settings:1. Custom Action Name: SETUPCOPYOEMINF2. DLL File: [SystemFolder]setupapi.dll3. Function Name: SetupCopyOEMInfA4. Parameter: string pointer, Constant, <Path to driver.inf file> (Don't enclose paths in double quotes)5. Parameter: long, Constant, NULL6. Parameter: dword, Constant, 17. Parameter: long, Constant, NULL8. Parameter: long, Constant, NULL9. Parameter: dword, Constant, 010. Parameter: long, Constant, NULL11. Parameter: long, Constant, NULL12. Return Value Type: dword13. Return Property: DLLRETURN· SetupUninstallOEMInf Function1. The SetupUninstallOEMInf function uninstalls a specified .inf file and any associated .pnf file. If the .inf file was installed with a catalog for signing drivers, the catalog is also removed. A caller of this function must have administrative privileges, otherwise the function fails.2. The SetupUninstallOEMInf function first checks whether there are any devices installed using the .inf file. A device does not need to be present to be detected as using the .inf file.3. If this flag is not set and the function finds a currently installed device that was installed using this .inf file, the .inf file is not removed.4. If this flag is set, the .inf file is removed whether the function finds a device that was installed with this .inf file.· Uninstallation Custom Action1. In the Execute Deferred section sequence an If Statement custom action prior to the RemoveFiles action. Make the execution of this action only apply on uninstall by giving it the condition REMOVE~="ALL"2. To this If Statement add a "Call Custom DLL From Destination" custom action with the settings:3. Custom Action Name: SETUPREMOVEFROMSOURCELISTA4. DLL File: [SystemFolder]setupapi.dll5. Function Name: SetupRemoveFromSourceListA6. Parameter: dword, Constant, 000001007. Parameter: string pointer, Constant, <Path to driver.inf file> (Don't enclose paths in double quotes)8. Return Value Type: dword9. Return Property: DLLRETURNMethod6Implementation Using DPInst.exe tool1. DPInst is a component of the Microsoft Windows Driver Install Frameworks (DIFx) that simplifies and customizes the installation of driver packages for devices that are not yet installed on a computer (commonly known as a software-first installation). DPInst also automatically updates the drivers for any installed devices that are supported by the newly installed driver packages.2. How Packages Install using DPInst3. By default, when the Microsoft® Windows® Driver Package Installer (DPInst) runs, it runs in a wizard-install mode that displays a sequence of wizard pages. In wizard-install mode, DPInst first displays a welcome page, and then displays an end-user license agreement (EULA) page. After the user accepts the licensing agreement on the EULA page, DPInst displays an installation page, and then performs the following steps to install Plug and Play (PnP) function drivers:· Locates the INF files. DPInst searches the directory where the DPInst executable (DPInst.exe) is located. DPInst also searches vendor-specified subdirectories under the directory where DPInst.exe is located. A vendor specifies the subdirectories by using the search and subDirectory XML elements in an optional DPInst descriptor file (DPInst.xml)· Authenticates the driver packages.· Preinstalls driver packages in the driver store.· Adds an Add or Remove Program entry in Control Panel that represents a driver package. (DPInst does not support this feature on Windows Longhorn.)· Installs the driver packages on matching devices that are connected to a computer.4. After DPInst completes the installation of a driver package, DPInst displays a finish page that informs the user of the status of the installation.5. DPInst supports a suppress-wizard mode that suppresses the display of wizard pages and other user messages that DPInst generates. It also supports command-line options that control the display of its wizard pages and other DPInst operations.6. For general information about INF files and driver packages, see "Providing a Driver Package" in the Microsoft Windows Driver Development Kit (WDK).Steps to Follow in MSI package
- To this If Statement add a "Call Custom DLL From Destination" custom action with the settings:
Step 1: Search for "*.inf" files in the captured folder.
Step 2: Cross check the contents of this file (step 1) with the contents of "*.inf" files under "[WindowsFolder]INF" folder.
Step 3: Delete the file "oemXX.inf" from "[WindowsFolder]INF" folder from your package.
Step 4: Copy DPInst.exe under the location where you get the ".inf" file.
Step 5: Write a custom action as shown below.
Repeat the above steps from 1 to 5 for each oemXX.inf files.
Now the MSI package created will be able to install the driver files without affecting the pre-existent application's functionality as well as the operating system.
Features of DPInst:
- Localization. There are two versions of DPInst: an English-only version and a multi-language version that supports many of the commonly used languages that Windows supports.
- Driver installation customization. You can localize and customize the text, icon, and bitmaps that are displayed on wizard pages. You can include branding, an optional EULA, and control whether wizard pages are displayed.
- Automatic driver package removal. For each driver package that is installed by DPInst, DPInst adds an entry to Add or Remove Programs (in Control Panel) where a user can remove the driver package from their computer. If the user removes a driver package, the package is removed from the driver store, the corresponding INF file is removed from the system INF file directory, and all devices that were previously supported by the package are updated with the next best available driver.
- Installation error logs. DPInst logs high-level messages in the DPInst log file (%windir%\DPINST.LOG). The log file is a plain-text file that contains information and error messages and identifies the driver package that was being installed when an error occurred.
Driver Package Installer (DPInst)DPInst Command-Line SwitchesMethod7Implementation Using Microsoft DIFx tool
Here I will discuss the Windows XP installation for a Signed Driver: ‘ClassFilter Driver’ with Wise Package Studio.Step by Step - Creating a driver installation with DIFx using Wise Package Studio1. Create a new Windows Installer (WSI) fileWork bench –> Tools –> Windows Installer EditorIf you do not get the ‘New Installation File’ window shown below, select File –> New from the main menu inside Windows Installer Editor(By default, the last edited .WSI file will be opened).Select Windows ApplicationAs this will be a Driver only installation we are renaming the default Wise feature from ‘Complete’ to ‘Drivers’.Note: If your own installation is to also contain non driver files (e.g. captured application files). Ensure there is a SEPARATE feature which will contain these.Installation Expert –> FeaturesRename the default feature from ‘Complete’ to ‘Drivers’2. Next, we add the DIFxApp Merge Module to the ‘Drivers’ FeatureMerge Modules –> AddSelect the DIFxApp Merge Module and click Next then Finish(if the Module is not present select ‘Download’ then ‘Wise Web Site’ to obtain it)Note: Make sure you are using at least version 2.0 of DIFxApp Merge Module.The DIFxApp Merge Module should then be visible.3. Create a folder EXCLUSIVELY for driver files.Note: If there is more than one driver (not the case with our example), there must be a SEPARATE folder for EACH driver and associated files.Open the Files view, then in the bottom window Right Click on ‘Program Files’ and select ‘New Folder’4. Add the relevant driver filesTo save experiencing a common problem (this issue will be detailed later), ensure the ClassAFilterDriver.inf file is added FIRST. Doing this step ensures the .inf file becomes the KeyPath for the component to contain the driver files.Highlight the ‘ClassFilterDriver’ folder in the bottom left window, then select ONLY the ClassAFilterDriver.inf.inf file in the top window and click the Add File button.The ClassAFilterDriver.inf file should be visible in the bottom right window as shown below.Next, add the remaining files to the ‘ClassFilterDrive’ folder:Check the ‘ClassFilterDrive’ folder is highlighted in the bottom left window, then select the remaining files in the top right window and click the Add File button.All files for a specific driver need to be in one root folder along with the .inf file for a successful installation via DifX.5. Configure Driver Installation OptionsDouble click on the ClassAFilterDriver.inf file in the bottom right window to set driver options.Installation Expert –> Files –> ClassAFilterDriver.inWhat to do if there is no Driver tabNote: If the Driver tab IS present, skip to the next section: ‘Configure Driver Installation Options (Continued)’This is a common problem with a relatively straight forward solution.Open Setup Editor from the bottom of your screen and select the Components tab at the top of the left window.Expand out each component in the left window and look in the relevant Files section until you find the ClassAFilterDriver.inf file.In our example below, the component containing the .inf file is called ClassAFilterDriver.inf. We can see that there is a small yellow key icon beside the in the ClassAFilterDriver.inf file in top of the right window.This means that the file is the KEYPATH for the component it is in.Setup Editor –> ComponentsIf the yellow key is NOT present beside the .inf file then it needs to be enabled:Right Click on the ClassAFilterDriver.inf file and click Set as KeyNote: If you are familiar with using the MSI Tables, the same as above can be achieved there: Reference ClassAFilterDriver.inf in the File table to find the relevant component name.Then, edit the KeyPath of the matching entry in the Component table.Configure Driver Installation Options (Continued)Under the Driver tab, ensure the ‘Use DIFxApp to install this driver file’ option is enabled.Enable the DIFxApp Installation Options to meet your preferences (these are described below).DIFxApp Installation OptionsRetain better-matching Pnp function driversEnabling this option will keep an existing Plug and Play driver on the computer if it is seen to be a better match (“better match” means if there is a signed and/or newer driver already on the computer this will be retained and the driver in this installation will not be installed).If you clear this checkbox, the installation's driver will be installed and over-ride any existing driver on the computer.Prompt for missing deviceEnabling this option gives a prompt and the end of the installation. This will occur if the matching device to the driver is NOT connected to the computer.Note: Even if this option is enabled, the prompt will NOT appear under a silent install.Create entry under Add/Remove ProgramsThis will add an entry under Add/Remove Programs for the driver(s) installed in ADDITION to the standard entry for the MSI installed.Configure the above DIFxApp Installation Options to your preferences then click OK to confirm.OS Specific Launch ConditionOnce all the steps above have been completed, consider what version of OS the driver is intended for. An ‘accidental’ rollout of out a Windows XP Driver Package to a Windows 2000 PC may not give very desirable results!The best safeguard is to condition the installation so it will only install on the intended OS.This can be achieved through setting System Requirements.Under Installation Expert in the left window select System Requirements.The relevant options to configure are Windows Version and Windows NT Version. These are shown highlighted in the right window below. Double click to edit them.In the case of our example our driver is intended for Windows XP, so we have set Windows Version (i.e. Windows 95, Windows 98 etc) to ‘Not supported’.Also the Windows NT Version has been set to ‘Windows XP’.The Message Text field defines the actual message to display if the OS Condition is NOT met.Installation Expert –> System RequirementsOnce this has been completed, compile your MSI and the Driver Package is ready to go!For Reference OnlyThe key table involved for a driver installation using DifX is the MsiDriverPackages table. The use of each column is as follows:ComponentShould have the name of the component containing the .inf file for the driver.FlagsA number which defines the type of driver to be installed, (Signed or Unsigned) along with the specific Installation Options.SequenceControls then install order of drivers (if there is more than one driver, lowest number installs first).Setup Editor –> Tables –> MsiDriverPackagesThe following are common examples of values for the Flags column:Signed Driver Installation7 = Signed driver install (Standard install with no options configured)6 = Signed driver install + “Retain better-matching PnP function drivers”5 = Signed driver install + “Prompt for missing device”3 = Signed driver install + “Create entry under Add/Remove Programs”Unsigned Driver Installation8 = Unsigned driver install (Standard install with no options configured)14 = Unsigned driver install + “Retain better-matching PnP function drivers”13 = Unsigned driver install + “Prompt for missing device”11 = Unsigned driver install + “Create entry under Add/Remove Programs”Note: Officially, the valid range that can be used in the Flags column is a number between 0 – 7.Because unsigned driver installations are ‘unsupported’ by Microsoft, the range for unsigned driver installations is 8 and above. Any of these options will show up as a table error (in addition it will appear as an ICE error if a validation is run). This is normal.Tip: For an unsigned driver installation you won’t be able to set the options via the interface in Wise (using the Driver tab of the .INF file). You will need to go into the MsiDriverPackages table and set the Flags value directly.
- If you are able to find all driver related files i.e. .INF, .Sys, .cat Then use DIFFAx tool (Microsoft Tool having Custom Action to implement Driver). To use the DIFFAx tool install the msi DriverInstallationTools.EXE