Solved

run regasm from inside executable

Posted on 2014-01-23
7
533 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

IoT Devices - Fast, Cheap or Secure…Pick Two

The IoT market is growing at a rapid pace and manufacturers are under pressure to quickly provide new products. Can you be sure that your devices do what they're supposed to do, while still being secure?

Question has a verified solution.

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

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

617 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