string a = Environment.ExpandEnvironmentVariables(@”%SystemRoot%\system32\sc.exe”);
string path = Directory.GetCurrentDirectory();
path += @”\TestWindowsService.exe”;
try
{
System.Diagnostics.ProcessStartInfo si = new System.Diagnostics.ProcessStartInfo(“cmd”);

si.RedirectStandardInput = true;

si.RedirectStandardOutput = true;

si.RedirectStandardError = true;

si.UseShellExecute = false;

si.CreateNoWindow = true;

si.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

System.Diagnostics.Process console = System.Diagnostics.Process.Start(si);
for (int i = 0; i < 100; i++)
console.StandardInput.WriteLine(“cd..”);

string command = a + ” create SycapCRMWindowsService  binPath= \”” + path + “\””;

console.StandardInput.WriteLine(command);
//Service has successfully been installed.
}
catch (Exception objException)
{
//objException.Message.ToString()
}

Advertisements