Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

run regasm from inside executable

Posted on 2014-01-23
7
Medium Priority
?
574 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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
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 2000 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

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

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

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
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 anti-spam), the admin…
Loops Section Overview

824 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