Click here to Skip to main content
13,766,627 members
Click here to Skip to main content
Add your own
alternative version


59 bookmarked
Posted 16 Jul 2007
Licenced CPOL

Downloading C# ActiveX Components through CAB File

, 24 Jul 2007
Rate this:
Please Sign up or sign in to vote.
This article describes the procedure to create an ActiveX Component in C#, download it from server and execute it on client side in Web based application.


This article describes how we solve the problem of registering the C# component after downloading it through CAB file and invoke it through script. It also gives the focus on how to update the latest version of component on the client machine when the component is getting installed through INF file execution.


In case of client side components created in C++, COM and ATL, the procedure is well defined and convenient as we just need to create the ActiveX component which exposes the Interface and create the CAB file including the INF file which describes whether to register it and where to copy it. This is not the case with ActiveX components created in C# as the Registerserver=Yes in INF file simply calls the regsvr32 on a given component, which is not useful to register the C# components.

Using the Code

Here the main focus is on how to create the CAB file and deploy it on the server. For that, create the C# application which exposes the COM interface. The following code demonstrates the simple C# component exposes the COM interface.

using System;
using System.Text;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace DownloadedApp
    interface IDownload
        void InvokeMethod();
    /// COM exposed .NET class.
    public class Download : IDownload
        /// COM exposed .NET Method.
        public void InvokeMethod()
            MessageBox.Show("Clientside component invoked successfully!!", 
		"Clientside component", MessageBoxButtons.OK, 

Now create the MSI Setup project in Visual Studio 2005 and give the output of this COM application to that project.

In the properties of Added output file in Setup project, make sure that the Register property is set to vsdrpCOM. Setting this property ensures the MSI file to register the ActiveX component using regasm tool in .NET. During installation, the installer itself takes care of registering this C# component to expose the COM interface.

Creating the CAB File

Using Microsoft InetSDK CABARC tool, we can create the CAB file including this DownloadDeployer.msi and INF file. This tool is freely available on Microsoft downloads website. For better execution and CAB download, it is good to sign the CAB file, we can get the code signing for our Component from the Microsoft site. It is beyond the scope of this article.

We also have another option to create the CAB file using Visual Studio 2005 Cab File Project which automatically includes the OSD file instead of INF file but to modify the OSD file is not an easy task as Visual Studio does not support extensive tools to modify it. Below is the sample of INF file which will be helpful to execute the MSI installer and to install the component on the Client machine.

[Setup Hooks]

run=msiexec.exe /i "%EXTRACT_DIR%\DownloadDeployer.msi" /qn

The script will contain code to invoke the ActiveX component. As the registration will already be done by the MSI installer, there will not be any problem while invoking the component through script. The script will be as mentioned below:

  <script LANGUAGE="JavaScript1.2">
   function Scrape( )
    var objDownload = new ActiveXObject( "DownloadedApp.Download" );
     objDownload.InvokeMethod( );
    catch(exception) {
     alert( "Failed" );
  <table align="center"> 
    <a href="javascript:Scrape( )">Invoke Component</a>
  <p>Please Wait...Downloading components...</p>
  <object name="secondobj" style='display:none' id='TestActivex'  



Here the version is the version of MSI file which we can modify by opening the *.vdproj file in Notepad, search for Product Version and change the version for any new updates. As given below, the view of *.vdproj file when opened in Notepad:

   "Name" = "8:Microsoft Visual Studio"
   "ProductName" = "8:DownloadDeployer"
   "ProductCode" = "8:{82CC6087-5430-4343-9F8B-207A889F92A1}"
   "PackageCode" = "8:{9D5DFC79-5E0F-4A6E-8796-10F08758FD2E}"
   "UpgradeCode" = "8:{21D008FF-E2BB-4C7B-A985-B20B9CB0C2D8}"
   "RestartWWWService" = "11:FALSE"
   "RemovePreviousVersions" = "11:TRUE"
   "DetectNewerInstalledVersion" = "11:TRUE"
   "InstallAllUsers" = "11:FALSE"
   "ProductVersion" = "8:1.0.0"
   "Manufacturer" = "8:Company Name"
   "ARPHELPLINK" = "8:"
   "Title" = "8:DownloadDeployer"
   "Subject" = "8:"
   "ARPCONTACT" = "8:Company Name"
   "Keywords" = "8:"
   "ARPCOMMENTS" = "8:"
   "ARPIconIndex" = "3:0"
   "SearchPath" = "8:"
   "UseSystemSearchPath" = "11:TRUE"
   "TargetPlatform" = "3:0"
   "PreBuildEvent" = "8:"
   "PostBuildEvent" = "8:"
   "RunPostBuildEvent" = "3:0"

In this file, the two important fields are ProductVersion and ProductCode. When we update the version of our component, make sure you change the Version of MSI file also. Which we can do by increasing ProductVersion manually by opening the *.vdproj file. Here one important thing to keep in mind is to change the ProductCode CLSID every time you increment the Version, but the UpgradeCode should be the same always to get the Component updated automatically on the client machine when we deploy the latest. Also make sure to change the RemovePreviousVersions to TRUE which will avoid creating multiple copies of the same component.

Points of Interest

The interesting point here is we have to increment the major version in object tag every time we increment the version of MSI file. It is because we have only 3 digit ProductVersion in the MSI file. One more thing is that the ProductCode should contain capital alphabets in its CLSID otherwise Visual Studio 2005 will give a compilation error while creating the MSI file.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Anand Todkar
Software Developer (Senior)
India India

You may also be interested in...


Comments and Discussions

GeneralRe: Getting an error when the cab is downloaded Pin
Anand Todkar19-Oct-07 1:10
memberAnand Todkar19-Oct-07 1:10 
GeneralRe: Getting an error when the cab is downloaded Pin
nachiketk19-Oct-07 1:45
membernachiketk19-Oct-07 1:45 
Generalinstall problem Pin
jzb28-Aug-07 20:01
memberjzb28-Aug-07 20:01 
GeneralRe: install problem Pin
jzb28-Aug-07 20:14
memberjzb28-Aug-07 20:14 
QuestionInstall Problem Pin
jimmy200623-Aug-07 0:13
memberjimmy200623-Aug-07 0:13 
AnswerRe: Install Problem Pin
Anand Todkar23-Aug-07 2:47
memberAnand Todkar23-Aug-07 2:47 
GeneralRe: Install Problem Pin
jimmy200623-Aug-07 4:27
memberjimmy200623-Aug-07 4:27 
GeneralRe: Install Problem Pin
Anand Todkar23-Aug-07 5:15
memberAnand Todkar23-Aug-07 5:15 
QuestionRunning applications Pin
vvat1-Aug-07 2:25
membervvat1-Aug-07 2:25 
AnswerRe: Running applications Pin
Anand Todkar1-Aug-07 2:47
memberAnand Todkar1-Aug-07 2:47 
Generalexternal DLL Pin
vvat27-Jul-07 1:15
membervvat27-Jul-07 1:15 
QuestionInstallation problem Pin
watoli24-Jul-07 5:34
memberwatoli24-Jul-07 5:34 
AnswerRe: Installation problem Pin
Anand Todkar24-Jul-07 6:18
memberAnand Todkar24-Jul-07 6:18 
GeneralRe: Installation problem Pin
watoli24-Jul-07 6:26
memberwatoli24-Jul-07 6:26 
GeneralRe: Installation problem Pin
Anand Todkar24-Jul-07 21:06
memberAnand Todkar24-Jul-07 21:06 
AnswerRe: Installation problem Pin
watoli24-Jul-07 23:09
memberwatoli24-Jul-07 23:09 
GeneralRe: Installation problem Pin
Anand Todkar24-Jul-07 23:23
memberAnand Todkar24-Jul-07 23:23 
GeneralRe: Installation problem Pin
GussGuss30-Jul-07 6:30
memberGussGuss30-Jul-07 6:30 
GeneralRe: Installation problem Pin
Anand Todkar31-Jul-07 6:02
memberAnand Todkar31-Jul-07 6:02 
QuestionRe: Installation problem Pin
wehowsky19-Sep-07 2:50
memberwehowsky19-Sep-07 2:50 
AnswerRe: Installation problem Pin
Deepankar6-Jun-09 2:00
memberDeepankar6-Jun-09 2:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01-2016 | 2.8.181114.1 | Last Updated 25 Jul 2007
Article Copyright 2007 by Anand Todkar
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid