Downloading C # ActiveX components through cab file

Source: Internet
Author: User
Tags microsoft downloads

    • Download Demo project-65.3 KB

This article describes how we solve the problem of registering the C # component after downloading it through cab file and invoke it through script. also gives the focus on how to update the latest version of component on 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 convinient 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 # AsRegisterserver = YesInINFFile simply callthe regsvr32 on given component, which is not useful to register te C # components.

Using the code

Here the main focus is on how to create the cab file and deploy it on server, for that create the C # application which exposes the COM interface, folowing 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 {[GUID ( D1E40FCE-E964-4dfd-B07E-BDE49D3519A1" )] Interface idownload {void invokemethod ();} ///              /// Com exposed. Net class.              /// [Classinterface (classinterfacetype. autodual)] [GUID ( A47C22B1-3CC3-45bc-801E-3FCC4FFD3E45" )] Public class download: idownload { ///              /// Com exposed. Net method.              /// Public void invokemethod () {MessageBox. Show ( "Clientside component invoked sucessfully !! " , "Clientside component" , Messageboxbuttons. OK, messageboxicon. Information );}}}

Now create the MSI setup project in VS 2005 and give the output of this COM application to that project.

In the properties of added output file in setup project, make sure thatRegisterProperty is setVsdrpcom. Seting this property insures the MSI file to register the ActiveX component using regasm tool in DOTNET. While installation, the installer itself takes care of registering this C # component to expose the COM interface.

Creating the cab file

Using MicrosoftInetsdk cabarcTool, 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 Microsoft Site. it is beyond the scope of this atricle.

We also have another option to create the cab file using vs. 2005Cab File ProjectWhich automatically provided desOSDFile instead of INF file but to modify the OSD file is not the easy task as Visual Studio does not support extensiove 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 client machine.

[Version] Signature = "$ Chicago $" advancedinf = 2.0 [setup hooks] hook1 = hook1 [hook1] 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 MSI installer there will not be any problem while invoking the component through script. the script will be as mentioned below.

& Lt; HTML & gt; & lt; Head & gt; & lt; script language = "javascript1.2" & gt; function scrape () {var objdownload = new activexobject ("downloadedapp. download "); try {objdownload. invokemethod () ;}catch (exception) {alert ("failed") ;}& lt;/script & gt; & lt;/Head & gt; & lt; body & gt; & lt; Table align = "center" & gt; & lt; TD & gt; & lt; a href = "javascript: scrape ()" & gt; invoke component & lt;/A & gt; & lt;/TD & gt; & lt;/table & gt; & lt; P & gt; please wait... downloading components... & lt;/P & gt; & lt; object name = "secondobj" style = 'display: none' id = 'testactivex 'classid = 'clsid: a47C22B1-3CC3-45bc-801E-3FCC4FFD3E45 'codebase = 'downloaddeployer. cab # version =, '& gt; & lt;/object & gt; & lt;/Body & gt; & lt;/html & gt;

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.

"Product" {"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" "arphelptelephone" = "8:" "arphelplink" = "8:" "title" = "8: downloaddeployer "" subject "=" 8: "arpcontact" = "8: company name" "keywords" = "8:" "arpcomments" = "8: "" arpurlinfoabout "=" 8: "" arpproducticon "=" 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 the make sure you change the version of MSI file also. Which we can do by increasingProductversionManually by openingVdprojFile. Here one important thing to keep in mind is to changeProductcode CLSIDEvery time you increment the version, butUpgradecodeShocould be same always to get the component get updated automatically on client machine when we deploy the latest. Also make sure to changeRemovepreviousversionsToTrueWhich wil avoid creating multiple copies of 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 versio of MSI file it is because we have only 3 digit productversion in MSI file. one more thing is the productcode shoshould contain capital alphabates in its CLSID other wise the VS 2005 will give compilation error while creating MSI file.

About Anand todkar

I am software engineer, interested in research in Microsoft technologies.

Click here to view Anand todkar's online profile.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.