Solved

run regasm from inside executable

Posted on 2014-01-23
7
489 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
A procedure for exporting installed hotfix details of remote computers using powershell
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

17 Experts available now in Live!

Get 1:1 Help Now