Solved

Register dll in c#

Posted on 2004-10-20
7
4,193 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Winform Module - What is the ASP.Net equiv 2 40
Need a simple RegEx to search for two words 27 87
asp web application 3 43
parsing question on dynamic concatenation 3 34
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

726 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