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

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.
BharatPrajapati212 13-Sep-14 8:46am    
may be your solution is at . check this link
BharatPrajapati212 13-Sep-14 8:47am    
And the detailed article about this is at
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)
string stEchoFmt = "# {0} run successfully. Exiting";
sIn.WriteLine(String.Format(stEchoFmt, QbatFile));
string results = sOut.ReadToEnd().Trim();
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