Solved

run regasm from inside executable

Posted on 2014-01-23
7
502 Views
Last Modified: 2014-01-31
can anyone tell me how to run the regasm.exe tool from inside an executable?  I have tried running it from a process, but it doesn't work (except on my own development machine).  Here's my code:

        string prog = @"C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm.exe";
        string asm = " " + phonePath + @"\MyAssembly.dll";
        string arg = asm + @" /codepath";
        RunProcessAsSrv(prog, asm);

        static void RunProcessAsSrv(String sRun, String sArg)
        {
            try
            {
                ProcessStartInfo pRegi = new ProcessStartInfo(sRun, sArg);
                pRegi.CreateNoWindow = true;
                pRegi.WindowStyle = ProcessWindowStyle.Hidden;
                pRegi.WorkingDirectory = System.IO.Path.GetTempPath(); 

                Process pReg;
                pRegi.UserName = "svc.admin@mydomain.com";
                String PassWd = "Password66";

                System.Security.SecureString SS = new System.Security.SecureString();
                foreach (char c in PassWd)
                    SS.AppendChar(c);

                pRegi.Password = SS;
                pRegi.CreateNoWindow = true;
                pRegi.WindowStyle = ProcessWindowStyle.Normal;
                pRegi.UseShellExecute = false;
                pReg = Process.Start(pRegi);
                pReg.WaitForExit(3000); // decreased time from 10 to 3 seconds

            }
            catch (Exception ex)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("Svc Run Error: " + ex.Message + Environment.NewLine + Environment.NewLine);
                sb.Append("Run Error: " + sRun + ": " + sArg + Environment.NewLine + Environment.NewLine);
                sb.Append("Trace: " + ex.StackTrace + Environment.NewLine + Environment.NewLine);
                sb.Append("Make sure the service account has local administrator permissions" + Environment.NewLine + Environment.NewLine);

                MessageBox.Show(sb.ToString(), "Error", MessageBoxButtons.OK);
            }

Open in new window


The service runs with an admin user with rights to the target machines.  The assembly has a strong name.  If I run the regasm from a command window it works just fine, but it won't execute from the executable.

I have also considered launching a powershell script to do this, but I'm not sure how to run it from inside (I'm sure I'm having a brain cramp on this!).
0
Comment
Question by:dhenderson12
  • 4
  • 3
7 Comments
 

Author Comment

by:dhenderson12
ID: 39803296
BTW, this is an internal application.  It is not available outside our domain.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39806313
Are you getting any errors, logging errors, ...?

Also, you should log the output of the command execution, using the Process.StandardOutput and StandardError stream readers.
0
 

Author Comment

by:dhenderson12
ID: 39806570
no, there's no error msg, it just doesn't do it, like it ignores the routine all together.
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 39806732
Are you saying that it doesn't execute "RunProcessAsSrv"?
0
 

Author Comment

by:dhenderson12
ID: 39806889
no, it runs,  but it doesn't actually do the registration.  I have to do it manually from a command prompt once the executable is done.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 39807266
Use something like this code to get the StandardOutput text:



pRegi.RedirectStandardOutput = true;

...
pRegi.WaitForExit(3000);

var output = pRegi.StandardOutput.ReadToEnd();

LogOutput(output);

Open in new window

0
 

Author Comment

by:dhenderson12
ID: 39823957
sorry for the long delay.

thanks, that helped me find the problem:  the path to the program files folder wasn't formatted correctly.  now I'll see if it works in deployment :)
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

777 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