-1

I've registered a .NET assembly using regasm.exe. Everything is fine but I have one problem. When I run registration from Admin user assembly is visible only by this user. Registration:

regasm.exe "C:\Assembly Path\MyAsm.dll" /codebase

So, how can I register assembly for all users?

Manfred Radlwimmer
  • 12,469
  • 13
  • 47
  • 56
Gleb
  • 1,190
  • 18
  • 43
  • 5
    `regasm` has nothing to do with the GAC. It only registers the COM interfaces exposed by your assembly, nothing more. You're probably looking for `gacutil`. – Frédéric Hamidi Jun 01 '16 at 09:29
  • @FrédéricHamidi that's my fault, I probably mean regasm.exe. – Gleb Jun 01 '16 at 09:35
  • Yes , agree with the @Frederic Hamidi , read this , https://msdn.microsoft.com/en-us/library/ex0ss12c%28v=vs.110%29.aspx – Roshan Jun 01 '16 at 09:36
  • 1
    So again, what are you trying to do: do you want to register a COM interface with Windows, or a .NET assembly with the assembly cache? The latter can contain the former, but should be done using a proper installer anyway (**not** `gacutil`, which is a development tool). **Why** are you using `regasm`, what do you think it does? What are you trying to achieve, how are you going to utilize this registration? – CodeCaster Jun 01 '16 at 09:41
  • See also [MSDN Blogs: Why to not use gacutil.exe in an application setup](https://blogs.msdn.microsoft.com/astebner/2006/11/04/why-to-not-use-gacutil-exe-in-an-application-setup/): _"Gacutil must not be called from a custom action. Gacutil is not designed to be used during installation"_. – CodeCaster Jun 01 '16 at 09:43
  • 3
    Anyway `regasm` not registering for all users simply means you don't have administrative privileges, making it register in HKCU instead of HKLM. – CodeCaster Jun 01 '16 at 09:47
  • @CodeCaster I write an addin for 3rd party system. To activate it in this system dll need to be registered by regasm.exe(as COM component). The problem is: when I register this dll from admin user no other user can see it, as it's registered only for admin. Question: how can I register dll for all users? – Gleb Jun 01 '16 at 09:48
  • _"when I register this dll from admin user"_ - using an elevated command prompt? – CodeCaster Jun 01 '16 at 09:49
  • @CodeCaster no, just Login to this machine as administrator and run registartion, – Gleb Jun 01 '16 at 09:52
  • 2
    Your installer toolchain should take care of this for you automatically, assuming that you set the proper switch. Which one are you using? It makes negative sense to write your own installation code. – Cody Gray Jun 01 '16 at 09:52
  • Yeah, so you need to actually run that command prompt As Administrator. – CodeCaster Jun 01 '16 at 09:52
  • @CodeCaster so you mean: 1. I login to windows as administrator. 2. Run cmd.exe with elevated preveliges. 3. Register dll. I'm right? – Gleb Jun 01 '16 at 09:57

1 Answers1

0

As @FrédéricHamidi mentioned, you need to use gacutil for .net-assemblies. Alternatively you can do this in code (requires elevation and can also be used to update dlls):

var publish = new System.EnterpriseServices.Internal.Publish();
publish.GacInstall("fullPathToDll");

If you have a Managed COM dll, make sure you are using the right version (64 or 32 bit) of regasm.exe (in that case, this question might be a duplicate of that question)

If you have an Unmanaged COM dll, use regsvr32

Community
  • 1
  • 1
Manfred Radlwimmer
  • 12,469
  • 13
  • 47
  • 56
  • The question seems to be about registering a COM DLL, not necessarily a .NET assembly. You also shouldn't use GacUtil (nor its API) on client machines; it's a development tool. – CodeCaster Jun 01 '16 at 09:38
  • That wouldn't be the first question where that'd be the case. The OP is clearly misguided, and this answer isn't going to help them I'm afraid. – CodeCaster Jun 01 '16 at 09:40
  • @CodeCaster True, maybe it can help someone who found this googling the right question. – Manfred Radlwimmer Jun 01 '16 at 09:45
  • Then _still_ you should not advise them to use `gacutil` nor its managed equivalent. It's even in the [docs](https://msdn.microsoft.com/en-us/library/system.enterpriseservices.internal.publish(v=vs.110).aspx): _"Publish is used internally by the .NET Framework. You do not need to use it directly in your code"_. – CodeCaster Jun 01 '16 at 09:46
  • @CodeCaster Emphasis on **do not need**, not **must not**. If he uses an installer, I agree - he shouldn't. Unfortunatley the question is not very detailed. I'll delete this answer if it turns out that he is doing, whatever he is trying to do, completely wrong. If someone wants to write an Installer/Updater of their own (like I did with this snippet), that's a valid approach. – Manfred Radlwimmer Jun 01 '16 at 09:50
  • Oh I'm not trying to force you to delete this answer, let that be clear. I'm just trying to clear up all the confusion. – CodeCaster Jun 01 '16 at 09:51