Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1762
  • Last Modified:

Can i call Regasm programatically?

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.

  • 4
  • 3
1 Solution
Bob LearnedCommented:
Can you show me what you have tried so far, and I can see if I spot any holes in your logic?

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
m4cc4Author Commented:
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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
m4cc4Author Commented:

I've tried the RegistrationServices class and it looks prommising except i get the following error
System.io.fileNotFoundException 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?

I have never seem that error before or that assembly
m4cc4Author Commented:
That article looks promising. I'll have to have a look and get back.
m4cc4Author Commented:
Thanks for your help, i've still not got it working, but i think i'm on the right track thanks to you.

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now