Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C# - ActiveX Control - How do I Install over the web

Status
Not open for further replies.

ahremsee

IS-IT--Management
Jul 15, 2007
1
GB
Hi,

Thanks for taking the time to read this.

I've just gotten my head around creating a COM Enabled Assembly in C#, its written using sharpdevelop so please bear that in mind when reading on.

This assembly is flagged in the project as registered for COM Interop and using the following code I can interact with it from a web page hosted on my local machine.

<object id="sample"
classid="clsid:A4B9C3C2-1234-451a-AEC1-DE3B042FB311"
height="426" width="326" >
</object>

If I use regasm to unregister this assembly, the page stops working. Which is what I am trying to fix moving forward.

Since I have this assembly running in a webpage I'd like to bung it into a CAB and have it install with the usual "do you want to trust" questions.

I've had a go using the cabsdk but I can't get it to work.
I've tried creating the cab, signing it and setting the codebase but all I get is a broken image on the webpage.

Does anyone have a list of gotchas or details on one they made earlier that I could crib from?

Best regards
Ahremsee
 
CAB is not suited for "ActiveX" components written in C# (please keep in mind that they're not actually 'real' ActiveX components, they're COM visible managed assemblies so that IE can create CCW - COM Callable Wrapper - to use the object in the same way it uses 'real' COM objects).

What I did to solve this problem was to create a setup project. Since I've never used it, I do not know if SharpDevelop has a setup wizard, so I'll just describe you the steps for Visual Studio:

1. File -> New -> Project -> Oher project types -> Setup and deployment -> Setup wizard. Select "Create a setup for a Windows application" and then click "Finish"

2. In the "Solution Explorer" right click the project and choose "View" -> "File System".

3. In the window that appears double-click "Application Folder". Right-click "Add" and select "File" (or "Project output" if the setup project in is the same solution with your C# ActiveX). Select the desired file (or project output) and click "Ok".

4. Right-click your ActiveX, choose "Properties window" and set the "Register" property to "vsdrpCOM". That means that the setup project will correctly register your assembly for COM.

5. Run "regasm <yourassembly.dll> /tlb. A <yourassembly.tlb> file will be created. Add the file to the project by following steps 3 and 4 but this time in step 5 set the "Register" property to "vsdrfCOM". This is for IE6 which will not load your ActiveX unless you register the tlb as well.

6. Build the project. A "Setup.exe" and a "YourProjectName.msi" will be generated. If you plan to deploy it on Windows 2000 and XP the .msi file is enough, the user will execute the .msi file and everything will be in order. For Vista you have to also deliver the setup.exe and the user has to execute the setup.exe otherwise you will get an error stating that the package is corrupt. Download "WinZip Self-Extractor" and create a "self-extract archive for software installation". This will allow you to tell "WinZip Self-Extractor" to automatically run "Setup.exe" after extracting the files. Create the .exe self-extract archive.

7. In the tag <object id="sample" add an "onerror" as it follows: <object id="sample" onerror="ActiveXNotInstalled();" ..... ></object>. This means that when IE will not find the CLSID you specified it will call ActiveXNotInstalled() JS function. In that function I redirect the user to a page where the link to the self-extract archive is and also some installation instructions.

It seems complicated but it isn't :) Give it a try.

P.S.: The benefit of this solution is that the user will see a "YourProjectName" in "Add/Remove Programs".
 
Ok, that's interesting. I'm not a C# person, but a VB6 person. If someone were asking this question and had written the component in VB6, I would say that you need to have a codebase parameter that references the cab file if you want the control to install when it isn't found on the local machine.

I don't know if that has any application here, but myu feeling is it doesn't hurt to mention it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top