?
Solved

Register dll in c#

Posted on 2004-10-20
7
Medium Priority
?
4,281 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 500 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month13 days, 14 hours left to enroll

801 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