JG Vimalan's Blog

It is all about coding!

Registering COM dll’s in the registry using C#.NET

This simple code in C# explains registering COM dll’s in registry.

using System.Diagnostics;

// Namespace required for Process class.

1. Create a batch(.bat) file

2. Write all the required dlls in register format using regsvr32 into the regdlls.bat file

3. Close the file and excute the batch file using process object.

private void RegisterDll()

{

StreamWriter sw=null;

//Create Batch file string path =

Application.StartupPath + \\regdll’s.bat;

FileInfo fw = new FileInfo(path);

try

{

if (fw.Exists) fw.Delete();

sw = fw.CreateText(); //Write the required dlls to batch file sw.WriteLine(“regsvr32 /s ” + @”””” + Application.StartupPath + “\\myDLL1.dll” + @””””);

sw.WriteLine(“regsvr32 /s ” + @”””” + Application.StartupPath + “\\myDLL2.dll” + @””””);

sw.WriteLine(“regsvr32 /s ” + @”””” + Application.StartupPath + “\\myDLL3.dll” + @””””);

sw.WriteLine(“regsvr32 /s ” + @”””” + Application.StartupPath + “\\myDLL4.dll” + @””””);

sw.Close(); // create instance of Process to execute batch file Process process = new Process();

process.StartInfo.FileName = path;

process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.Start();

process.WaitForExit(10000);

fw.Delete();

}

catch { }

}

RUN regedit you can find the COM dll’s registered under, My Computer\HKEY_CLASSES_ROOT\

Regards,

JG Vimalan

Advertisements

September 27, 2009 - Posted by | C#.NET

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: