Can i call Regasm programatically?

Posted on 2007-10-17
Last Modified: 2013-12-17
Hi All,

I've got a problem where i have written a small program to copy some files off a server onto client machines. The copying runs under the Administrator account using impersonation.
Some of these files are .net dlls which need to have regasm run on them.
Is there a way to do this in the program with code? I've tried using System.Diagnostics.Process to open a bat file using runas with the administrator username and password (password is piped in using sanur) but that doesn't always seem to work(says it cant locate Runas as a process).
Ideally i'd like to have a list of dll's that need registering and use some c# to register them.

Question by:m4cc4
    LVL 96

    Expert Comment

    by:Bob Learned
    Can you show me what you have tried so far, and I can see if I spot any holes in your logic?

    LVL 21

    Expert Comment

    Yes you can call it programtically using System.Diagnostics.Process.Start(directorypath+"Regasm","c:\ddlname.dll");
    Even thought this isnt exactly programatic, it will help you achieve the regasm functionality using code

    Author Comment

    This is the code that does the regasm at the moment. I have a few to do and the list may increase so i use a bat file to do the regasm bits running as administrator. It runs on my machine but not on other machines even though they are set up in the same way.

    ProcessStartInfo startInfo = new ProcessStartInfo("cmd.exe");
    startInfo.UseShellExecute = false;
    startInfo.LoadUserProfile = false;
    startInfo.WindowStyle = ProcessWindowStyle.Hidden;
    startInfo.RedirectStandardOutput = false;
    startInfo.RedirectStandardInput = false;
    startInfo.WorkingDirectory = @addInDir;
    startInfo.Arguments = "/C " + "runas /env /user:Administrator@companyname register.bat | sanur Password";
    startInfo.CreateNoWindow = true;

    Process p = new Process();
    p.StartInfo = startInfo;

    This all runs inside this.
    if (ImpersonationUtil.Impersonate("Administrator", "Password", "company"))
    Which impersonates the Administrator account and works fine for copying files.

    I was hoping for some sort of Registry functions to solve this instead of having to use regasm.

    Thanks for any suggestions

    LVL 21

    Expert Comment

    well you cannot use the registry functions because REGASM just doest write the name of the component to the registry, rather it reads the metadata from the component and writes some more information.

    You might want to check out the RegistrationServices Class to do the same thing

    Author Comment


    I've tried the RegistrationServices class and it looks prommising except i get the following error Could not load the file or assembly 'Interop.EverestAddin'

    It happens on this line of code
    if (reg.RegisterAssembly(asm, AssemblyRegistrationFlags.SetCodeBase))

    The files are all in the same directory so i dont know what its complaining about.
    Is there anything i can do to make it find it or is this another dead end?

    LVL 21

    Accepted Solution

    I have never seem that error before or that assembly

    Author Comment

    That article looks promising. I'll have to have a look and get back.

    Author Comment

    Thanks for your help, i've still not got it working, but i think i'm on the right track thanks to you.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Flash ( has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
    Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    760 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

    8 Experts available now in Live!

    Get 1:1 Help Now