Solved

How can I register a COM enabled .net dll's type library (.tlb) file programmatically on a user's pc?

Posted on 2008-06-16
9
3,827 Views
Last Modified: 2012-05-05
I have a .net COM enabled dll MyDll.dll which I wish to call from Excel 2003 VBA on client pcs.  The setup package project I have created in Visual Studio 2008 will successfully register the dll on the client pc, but doesn't seem to be able to register the type library file, MyDll.tlb which it distributes along with the dll file  

I can generate and register a new copy of the tlb file on the client pc via running (from a command line, as admin user, and from the .net v2 directory) regasm pathtoMyDll.dll /codebase /tlb but this is tedious to do on 40-50 pcs.  
How can I automate the process? Or should I be doing things a different way?

(My clients are usually running Windows XP and Office 2003)
0
Comment
Question by:patrick_exe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 21798242
Did you use the Excel add-in template to create the .dll? Did you set the build properties to Register for COM Interop?
0
 

Author Comment

by:patrick_exe
ID: 21799083
Technically, it is not an add in (it is unnecessary for it to be one), it is just a .net class library, with both "Register for COM Interop" and "Make COM visible" ticked.  It is also <strong>not</strong> signed (contrary to what Microsoft say, it is <strong>not</strong> necessary to put dlls in the Global Assembly Cache, nor is it necessary to make them strongly signed when using the /codebase flag with regasm).

For a very simple project, such as the one in the code snippet below, all that seems necessary for Excel VBA to be able to use the dll is that 1) the dll and tlb files generated by Visual Studio 2008 be placed in the same folder (e.g c:\test) on the client pc, 2) the dll be registered using (when running as admin from a command line) regasm "c:\test\COMEnabledClassLibrary.dll" /codebase and 3) that the VBA project have a reference to the tlb file.

My real life project has many more interfaces, classs and methods, including some with generics (which I know can't be exported to COM, but I'm not using those particular methods from COM, only from .net).  On some pcs, all that is needed is the three steps above. On some others, I get an "Object library not registered" error either at compile or run time in the Excel VBA project, and I can solve this by registering the COMEnabledClassLibrary.tlb file, either without regenerating it by 4a) running regtlibv12.exe "c:\test\COMEnabledClassLibrary.tlb", or by regenerating it by 4b) running regasm "c:\test\COMEnabledClassLibrary.dll" /codebase /tlb, in each case as administrator.

Aside from the issue of how to automate things (and thus avoid administrators at my clients having to run regasm or regtlibv12 from a command line), two things are puzzling about this: why the tlb file needs registering on some pcs but not others, and why the tlb file needs regenerating on some pcs and not others.  The original tlb file must include file paths on my development pc which do not match up with the deployment path on the client pc (in this example c:\test\), so if the tlb file needs registering at all I would have thought that it needed to be regenerated so that the correct path(s) could be stored in the registry, however VBA manages to get round that on some pcs.

For pre .net COM dlls (e.g. those generated by VB6), simply setting a reference to the dll in a VBA project was enough to register the dll, but for a .net COM enabled dll (such as I am using), it is not clear to me exactly what setting a reference to the .tlb file does.  Perhaps it registers the tlb file on some pcs, registers both the tlb and dll file on others, and simply enables the VBA project to compile on others without doing any registration.  (If so, that might explain why different actions are necessary on different pcs).  

I can run regasm with /codebase and /regfile to produce a .reg file which (without registering the dll or tlb file) shows me the registry entries needed to register the dll, but not the tlb file (one can't run regasm with both /regfile and /tlb, which seems silly, or at least Microsoft ought to have provided a way of producing a reg file with just the registry entries needed to register the tlb file).
Regtlib.exe and its successor regtlibv12.exe, which seem to be deprecated by Microsoft (they seem to have disappeared from my Vista pcs after some recent Windows updates, and don't seem to be documented properly, might provide information as to what registry entries are needed for a tlb file (e.g. if they allow a similar /regfile flag but I can't find any documentation that suggests that they do - I may try it as an experiment).
// 16 Jun 2008 Simple .net 3.5 C#Project to provide a minimum COM enabled (via Make COM visible and Register for COM Interop project properties) library
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace COMEnabledClassLibrary
{
 
    /// <summary>
    /// 
    /// </summary>
    public interface ICOMTestClass19
    {
        /// <summary>
        /// 
        /// </summary>
        int ReturnSeven();
     
    }
 
    /// <summary>
    /// 
    /// </summary>
    public class TestClass19 : ICOMTestClass19
    {
 
        #region ICOMTestClass19 Members
 
        public int ReturnSeven()
        {
           return 7;
        }
 
        #endregion
    }
}
 
// the corresponding simply VBA client code using this is
Public Sub Test
Dim obj as ICOMTestClass19
Set obj = new TestClass19
dim i1 as Long
i1 = obj.ReturnSeven
End Sub

Open in new window

0
 

Author Comment

by:patrick_exe
ID: 21807627
Update: I have tested regtlibv12.exe and it ignores any /regfile flag so that can't be used to produce a .reg file with registry entries needed to register the .tlb file.
You experts might also like to know a bit of background: this is for a network installation of my software.  The dll and .tlb file are installed on a shared folder on the network, and each pc has been configured (via caspol) to trust software in that precise location (otherwise .net security by default won't allow the code in the dll to run).

Our client doesn't want to have to run a Windows Installer package on each pc, so, given the relatively small number of files involved (effectively just the dll and tlb file) putting the dll and tlb file in a shared folder on the network and getting them registered for each pc in an automated way seems to be the best way to deploy the software (with Excel VBA as one of the front ends).  Until recently, the registration has been done via login scripts (.bat files running [with admin rights] regasm pathtodllfile /codebase) but on a few pcs the tlb file seems not to have been registered (whereas it had been on the majority of pcs, possibly [as surmised above] via Excel VBA setting a reference to the tlb file), so we tried amending the .bat scripts to run regasm pathtodllfile /codebase /tlb: pathtotlbfile but the scripts seem to have failed silently, hence the need to run regasm pathtodllfile /codebase /tlb: pathtotlbfile as admin from the command line on each pc.
Am investigating why the scripts failed by getting them to report success/failure and to pause before being dismissed by the user, but any insights you can offer as to a) whether setting a reference in Excel VBA to a .tlb file sometimes registers the tlb file, and b) other advice if you would deploy things differently will be appreciated.
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 17

Expert Comment

by:Shanmuga Sundaram
ID: 21877335
Did you try registering as below

regasm/codebase yourdotnetdll.dll /tlb:yourdotnetdll.tlb
0
 
LVL 17

Expert Comment

by:Shanmuga Sundaram
ID: 21877337
I forget to mention you to do that from the command prompt
0
 

Author Comment

by:patrick_exe
ID: 22045865
shasunder: (apologies for not replying earlier, somehow I missed your post) if you read my comment of 06.17.2008 at 10:22PM BST immediately before yours, you'll see that in the end we had to do precisely what you suggested:

regasm pathtodllfile /codebase /tlb: pathtotlbfile as admin from the command line on each pc.

so I'm afraid your comment doesn't add anything new.  

I conclude that this is an area where noone seems to know the answer (or perhaps people at Microsoft do, but if so, they aren't posting on this exchange.)
I am going to suggest to the admins that this post remain as unsolved, because it at least offers some suggestions of things to try and some manual solutions if others are looking at this area.


 
0
 

Author Comment

by:patrick_exe
ID: 22045878
The learned one:
Rather than classify this question as abandoned and deleting it, I suggest leaving it with some other status, e.g. unsolved, because it at least offers some suggestions of things to try and some manual solutions if others are looking at this area.
Regards
Patrick
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 22084971
PAQed with no points refunded (of 500)

Computer101
EE Admin
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question