Solved

Register dll in c#

Posted on 2004-10-20
7
4,238 Views
Last Modified: 2012-06-27
Please help,
is there a way to register/unregister dll files programmatically in c# (like calling regsvr32)?
Many thanks!
0
Comment
Question by:zaratin
[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
7 Comments
 
LVL 8

Expert Comment

by:AaronReams
ID: 12363525
You could use the PInvoke feature of C# to call ShellExecute or _spawn.  Then use either of those functions to call regsvr32 <your.dll> (or regsvr32 -u).





0
 
LVL 8

Accepted Solution

by:
AaronReams earned 125 total points
ID: 12364047
Here is the actual code to do it...
I tested the following and it works.  let me know if you have any other questions.  Also you can check the flags for regsvr32 and suppress the registration successful message box if you want by running it in silent mode.   Good luck -Aaron


// Add this to the top of your file
using System.Runtime.InteropServices;

// Add this to your class
[DllImport("shell32.dll", CharSet=CharSet.Auto)]
public static extern int ShellExecute(int hwnd,string lpOperation,string lpFile,string lpParameters,string lpDirectory,int nShowCmd);

// This performs the registration
private void button1_Click(object sender, System.EventArgs e)
{
     ShellExecute(this.Handle.ToInt32(),"open","regsvr32.exe",@"c:\MyTest.dll",@"C:\",0);
}


0
 
LVL 11

Expert Comment

by:Buffon
ID: 12364401
I think  zaratin ment to register c# dll. You can add c# dll to GAC(Global Assembly Cash)  with gacutil.exe (you can find this utility on your harddisk, it comes with .net framework).
gacutil -i mydll.dll

And then you can load this assembly using Reflection. If you need sample source code, I'll be able to post it in 8-9 hours (I am not home right now)
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 7

Expert Comment

by:God_Ares
ID: 12367818
are you using asp.net? if so there's probbably no need for you to registre your dll with the machine.
0
 
LVL 11

Expert Comment

by:Buffon
ID: 12368670
Thats the sample for using Reflection:

Assembly a = Assembly.LoadWithPartialName("myassembly");
Type t = a.GetType("namespace.classname");
obj = (MyApp)Activator.CreateInstance(t, args);
obj.go(); // if MyApp implements some interface with go() function
0
 

Author Comment

by:zaratin
ID: 12374452
Thanks everyboy for your quick and numerous postings! I've got to say that Aaron gave the perfect answer, it was just what I was looking for. Many thanks!!!  Thanks again everybody for your collaboration...
0
 
LVL 8

Expert Comment

by:AaronReams
ID: 12374480
Glad I could help.  Happy coding!

Cheers,
Aaron
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

691 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