Making a CAB file which doesn’t prompt for installation location

来源:互联网 发布:lrc字幕制作软件 编辑:程序博客网 时间:2024/05/13 21:47

Screenshot showing application being installed on a Windows Mobile deviceWhendeveloping bespoke line of business applications it is common for yoursolution to require some form of hard reset recovery.

A common technique for implementing this is to package theapplication as a CAB file and then use a device specific technique toensure that this file survives and automatically installs after a hardreset.

One problem you may come across in implementing this scenario is that a Smart Device CAB projectcreated by Visual Studio will by default prompt the user to selectwhere to install the application if one or more storage cards arepresent. This blog post covers one technique to remove this prompt whenyou want to reduce user interaction and need to hard-code theinstallation location of your application.

Finding an explanation

The first step towards finding a solution is to determine the reasonwhy we are seeing the current behaviour. We can find an answer withinthe User Selected Installation section of the CAB Wizard documentation available on MSDN. This document states the following:

The user is prompted for the preferred installation volume only if the following two conditions are met:

  1. The application developer has created an %installdir% variable in the [CEStrings] section of the .inf file.
  2. The device has more than one storage volume available (such as a secondary MultiMedia card storage).

We obviously can not control the number of storage volumes presenton a user’s device, but what is an *.inf file and how can we controlthe content of it’s [CEStrings] section?

Manually rebuilding a CAB file

The Smart Device CAB project type within Visual Studio is a simple GUI front end to a command line utility called CAB Wizard (cabwiz).When Visual Studio builds your project it takes the settings you havespecified and behind the scenes generates a specially formatted textfile (an *.inf file) which instructs the command line utility how tocreate your application’s CAB file.

Unfortunately for us the Visual Studio IDE always includes an%installdir% variable within the [CEStrings] section of the file itgenerates and there is no option that allows us to override thisbehaviour.

One possible work around to remove this variable is to allow VisualStudio to generate it’s *.inf file and then manually edit it and re-runthe cabwiz utility by hand.

First we need to determine where the *.inf file is stored and theproper command line required to execute cabwiz.exe. This informationcan easily be found by looking at the Output Window of Visual Studioafter you build your solution. Near the end of the log you should see asection that looks similar to the following:

------ Build started: Project: BespokeLOBApplicationCAB, Configuration: Debug ------
Building file 'C:/BespokeLOBApplicationCAB.cab'...
 
"C:/Program Files/Microsoft Visual Studio 9.0/smartdevices/sdk/sdktools/cabwiz.exe"
"C:/Project/BespokeLOBApplicationCAB.inf"
/dest "C:/Project/"
/err CabWiz.log
 
Windows CE CAB Wizard

If you open the inf file specified in the above command line youshould be able to find and then delete a line declaring the%installdir% variable (as highlighted in the screenshot below).

Screenshot showing the line which needs removed from the CAB's *.INF file

Once you have saved this change the last step is to open a MSDOScommand prompt window and execute the command line discovered above tore-generate your CAB file. This new CAB file won’t prompt for aninstallation directory due to the lack of the %installdir% variable.

One thing to be aware of is that removing the %installdir% variablemeans placing files in the “Application Folder” directory within theFile System Editor window will cause an error when you run cabwiz.Instead you should build up your directory structure by hand by rightclicking in the file system editor and selecting the option to add newCustom Folders.

Sample Application

[Download BespokeLOBApplication.zip - 18.1KB]

A small sample application is available for download whichdemonstrates this technique. A “dummy” application calledBespokeLOBApplication is packaged into a CAB file via a Smart DeviceCAB project.

Notice if you build the CAB via the Visual Studio interface that theuser will be prompted to select an installation location even thoughevery file specified in the filesystem editor is deployed to a hard-coded location.

If you then alter the CAB file using the technique outlined abovethe user will not be prompted to select an installation location duringinstallation.

For your convenience the download also contains two pre-built cabfiles called BespokeLOB_Prompt.cab and BespokeLOB_NoPrompt.cab todemonstrate the principal.

One disadvantage of this technique is that manual edits to the *.inffile will be lost the next time you rebuild your project via VisualStudio. If the structure of your CAB file does not change that oftenone solution is to remove the Smart Device CAB project from yoursolution and instead build your CAB file by executing the command linediscovered above via a custom Post Build step.

原创粉丝点击