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;
}
}
}
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;
}
}
}
Raaj KumarPosted Feb 25, 2010, 5:12 AM
For getting the svcutil and installutil exe path you can read the Registry in custom action and get the path. But you need to append few lines to complete the path settings. For getting the SVCUTIL path,
Key= [HKEY_LOCAL_MACHINE\SOFTWARES\MICROSOFT\Microsoft SDKs\Windows\v6.0A]
Physical Path= C:\Program Files\Microsoft SDKs\Windows\v6.0A\
so here you have to append a string bin\svcutil.exe to the physical path.
For installutil do the same thing and here is the key and physical path,
KEY = [HKEY_LOCAL_MACHINE\SOFTWARES\MICROSOFT\.NETFRAMEWORK]
Physical Path = C:\WINDOWS\Microsoft.NET\Framework\
Regards,
Raaj