Solved

Register dll in c#

Posted on 2004-10-20
7
4,152 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
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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

786 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