Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
1.80/5 (3 votes)
Hi,

My requirement is that can a windows service automatically install, start and Uninstall the other windows services programmatically using c#. Means there is a master services which dynamically invoke the child services.
Posted
Comments
BharatPrajapati212 13-Sep-14 8:46am    
may be your solution is at http://stackoverflow.com/questions/358700/how-to-install-a-windows-service-programmatically-in-c . check this link
BharatPrajapati212 13-Sep-14 8:47am    
And the detailed article about this is at
http://www.c-sharpcorner.com/UploadFile/sachin.nigam/InstallingWinServiceProgrammatically11262005061332AM/InstallingWinServiceProgrammatically.aspx
gggustafson 14-Sep-14 12:31pm    
You must implement the install, start, and uninstall methods yourself. The "master services" that you seek is called the Service Control Manager.

Implementing install, start, and uninstall is complicated only in that they require careful step-by-step operations. Otherwise, they are straight forward.

If you want additional information, reply to this comment.
Bernhard Hiller 15-Sep-14 4:08am    
And where are you stuck?

1 solution

This solution works for me......

public void ProcessBatFile(string QbatFile)
{
ProcessStartInfo psi = new ProcessStartInfo("cmd.exe");
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.RedirectStandardInput = true;
psi.RedirectStandardError = true;
psi.WorkingDirectory = @"C:\inetpub\websites\services\";
Process proc = Process.Start(psi);
StreamReader strm = System.IO.File.OpenText(QbatFile);
StreamReader sOut = proc.StandardOutput;
StreamWriter sIn = proc.StandardInput;
while (strm.Peek() != -1)
{
sIn.WriteLine(strm.ReadLine());
}
strm.Close();
string stEchoFmt = "# {0} run successfully. Exiting";
sIn.WriteLine(String.Format(stEchoFmt, QbatFile));
sIn.WriteLine("EXIT");
proc.Close();
string results = sOut.ReadToEnd().Trim();
sIn.Close();
sOut.Close();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900