Link to home
Start Free TrialLog in
Avatar of m4cc4
m4cc4

asked on

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.

Thanks.
Andrew
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

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

Bob
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
Avatar of m4cc4
m4cc4

ASKER

Hi,
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;
p.Start();
p.WaitForExit();
p.Close();
p.Dispose();

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

Andrew
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
Avatar of m4cc4

ASKER

Thanks,

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))
{
       MessageBox.Show("Registered!");
}

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?

Andrew
ASKER CERTIFIED SOLUTION
Avatar of surajguptha
surajguptha
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of m4cc4

ASKER

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

ASKER

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