Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

run regasm from inside executable

Posted on 2014-01-23
7
Medium Priority
?
551 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
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.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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.
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

660 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