Register, Start and Install Com+ dll during installation

Feb 15 2010 5:43 AM
Hi.. I am making an installer.

I want to register , start and install my com component dll during the installation.


So I wrote the following code... (Custom Action) ..... It works absolutely fine but the problem is i have to hardcode the svcutil and installutil exe path.... is there anyway to avoid this?

And one more question do I have to Set any Credentials for this operation? As still I didn't test on the Other machine..


[RunInstaller(true)]
    public partial class RegisterSvc : Installer
    {
        public override void Commit(System.Collections.IDictionary savedState)
        {
            base.Commit(savedState);
            if (ExecuteRegCommand(Context.Parameters["target"].ToString() + Context.Parameters["dllname"].ToString()))
                ExecuteInstallUtilCommand(Context.Parameters["target"].ToString() + Context.Parameters["dllname"].ToString());
        }
        public Boolean ExecuteRegCommand(string command)      // REGISTER THE COMPONENT DLL
        {
             if (ExecuteCommand(Context.Parameters["regsvcspath"].ToString(), command))
             {
                    // START THE COMPONENT SERVICE
                    var objAdmin = new COMAdmin.COMAdminCatalog();
                    objAdmin.StartApplication(Context.Parameters["componentname"].ToString());
                    return true;
             }                  
          
             return false;
        }
        public Boolean ExecuteInstallUtilCommand(string command) // INSTALL COMPONENT
        {
           
           
                ExecuteCommand(Context.Parameters["installutilpath"].ToString(), @"/url=""" + Context.Parameters["urlpath"].ToString() + "\" " + command);
                return true;
           
           
        }
        Boolean ExecuteCommand(string fileName, string command)
        {
            try
            {
                System.Diagnostics.ProcessStartInfo procStartInfo =
                    new System.Diagnostics.ProcessStartInfo(fileName, command);
                procStartInfo.RedirectStandardOutput = true;
                procStartInfo.UseShellExecute = false;
                procStartInfo.CreateNoWindow = true;
                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.StartInfo = procStartInfo;
                proc.Start();                
                string result = proc.StandardOutput.ReadToEnd();
                Console.WriteLine(result);
                return true;
            }
            catch (Exception objException)
            {
                return false;
            }
        }
    }

Answers (1)