Solved

Register dll in c#

Posted on 2004-10-20
7
4,112 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 7

Expert Comment

by:God_Ares
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Glad I could help.  Happy coding!

Cheers,
Aaron
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now