Monday 15 December 2014

Getting an Offline Copy of Windows Driver Kit (WDK)

Microsoft provides a web installer for WDK but not an ISO image. If you want an offline copy, you have to execute it to download everything. The problems are:

  1. If the online computer is sufficiently locked down, you might not be able to execute it.
  2. Even if you are allowed to, it insists on installing .NET 4.5 if it is missing. This is bad because downloading shouldn't require installation of anything.
  3. Even if you let it install .NET 4.5, it can't unless it has administrative privileges.

Instead of executing the installer, we can extract download information from it and download accordingly.

Procedure

  1. Download the web installers from a online computer from here. There are actually two files: wdksetup.exe and wdktestsetup.exe. The first installer installs WDK proper and the second installs WDK Test Pack. Download both.
  2. If the online computer is somewhat locked down, take the downloads to another computer that you have more control of, and perform your work there.
  3. Use 7-zip to extract wdksetup.exe as if it were an archive.
  4. Check that you have these files:

  5. Open the file u12 with a text editor. (It contains XML data.)
  6. Locate the line that contains the downloadroot tag:
    <downloadroot>http://go.microsoft.com/fwlink/?LinkID=392876</downloadroot>.

    This URL redirects to a top level remote directory that contains our download files.

  7. We need to figure out exactly what this directory is. On the online computer, open a web browser, type this address in the address bar, and press enter.

    Ignore the 404 error which isn't important. We want the redirection result, which is reflected in the address bar:

    http://download.microsoft.com/download/0/8/C/08C7497F-8551-4054-97DE-60C0E510D97A/wdk

    Let's call this URL $T.

  8. Go back to the computer you have been using (see step 2). Close the file u12.
  9. Open the file 0.
  10. To make viewing easier, insert a carriage return after every close tag. The following isn't exactly correct but will do: if you use Notepad++, try 'find-and-replace'. First, set the search mode to 'Regular expression'. Next, the 'Find what' field should be > and the 'Replace with' field should be >\n. Then, click 'Replace All'.

  11. Notice the lines that begin with the tag <Payload id="..." />. Basically they describe what you need to download. Other lines aren't important.
  12. Skipping those lines with attributes Packaging="embedded". They describe files that aren't downloaded but are extracted from the web installer itself. Notice the SourcePath attributes. Compare with the screenshot in step 4. Does it ring a bell?
  13. Take note of the lines with attributes Packaging="external". For each line, you must
    • record the FilePath attribute. It specifies where a file should be downloaded to, relative to the location of the web installer. If a file with matching file size and hash isn't there, the installer will download into that place. Put it differently, it expresses directory layout for placing downloads.
    • record the download URL. There are two cases.
      • If DownloadUrl attribute is present, used as the download URL.
      • If absent, the download URL is derived from the SourcePath attribute. First, convert all backslashes in SourcePath to forward slashes, then append the result to $T (step 7) to give the download URL. For example, if SourcePath is

        Installers\1c33d17316f25da4cbe42ca09b018509.cab

        then the download URL would be:

        http://download.microsoft.com/download/0/8/C/08C7497F-8551-4054-97DE-60C0E510D97A/wdk/Installers/c33d17316f25da4cbe42ca09b018509.cab.

    To avoid confusion, when recording FilePath attributes, convert all backslashes to forward slashes.

  14. Put the download URLs and FilePath attributes into two separate files, url.txt and filepath.txt.

    url.txt would look like:

    http://download.microsoft.com/download/0/8/C/08C7497F-8551-4054-97DE-60C0E510D97A/wdk/Installers/1c33d17316f25da4cbe42ca09b018509.cab http://download.microsoft.com/download/0/8/C/08C7497F-8551-4054-97DE-60C0E510D97A/wdk/Installers/b6923fe117b94abbb1703c09cf619759.cab
    .
    .
    .

    whereas filepath.txt would look like:

    Installers/1c33d17316f25da4cbe42ca09b018509.cab Installers/b6923fe117b94abbb1703c09cf619759.cab
    .
    .
    .

  15. You now have url.txt and filepath.txt. Use the former for downloading and latter for moving the downloads to a proper directory layout. Typically, you use some kind of scripts for that purpose, e.g. with Cygwin bash script or Powershell scripts.
  16. Once you have downloaded everything into right place, put wdksetup.exe to the top level download directory. Now you have an offline copy of WDK.
  17. Repeat steps 3 to 16 differently:
    • In step 3, open wdktestsetup.exe instead.
    • In steps 5 to 8, open u11 instead.
    • In step 14, save the download URLs to a different file; e.g. urltest.txt.
    • In step 15, save the file paths to a different file; e.g. filepathtest.txt.
    • In step 16, put wdktestsetup.exe to the top level download directory instead.
  18. You now have an offline copy of WDK Test Pack.

Extra Remarks

  1. Although you can carry out steps 11 to 15 by hand, you'd better use some kind of scripting; e.g. Cygwin shell script or Powershell script.
  2. We separate the download information into download URLs and directory layouts, and place them into different files. The reason is that each has a different purpose.
  3. If during download you get 404 errors, it is OK: there could be lines in u12 and u11 that are not used by the web installers and have no corresponding files on the server. Try doing a full install from the resulting download trees. If the installers report success, then these 404 errors are harmless.