Windows服务可以安装,启动和安装吗?卸载子Windows服务 [英] Can a Windows service install,start & uninstall child Windows service
本文介绍了Windows服务可以安装,启动和安装吗?卸载子Windows服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的要求是Windows服务可以使用c#以编程方式自动安装,启动和卸载其他Windows服务。意味着有一个动态调用子服务的主服务。
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.
推荐答案
这个解决方案对我有用......
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 \;
流程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}运行成功。退出;
sIn.WriteLine(String.Format(stEchoFmt,QbatFile));
sIn.WriteLine(EXIT);
proc.Close();
string results = sOut.ReadToEnd()。Trim();
sIn.Close();
sOut .Close();
}
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();
}
这篇关于Windows服务可以安装,启动和安装吗?卸载子Windows服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文