日期:2014-05-18  浏览次数:20840 次

winform中 怎么 添加删除服务 启动停止服务??
我写了一个服务,在程序界面上有4个按钮 添加服务 删除服务 启动服务 停止服务

用程序,怎么实现啊??

要具体代码,呵呵

------解决方案--------------------
用 Process 类去做这个事情,传入命令字符串即可
开始:net start [服务名]
停止:net stop [服务名]
------解决方案--------------------
做个标记。。。这功能很给力
------解决方案--------------------
[code=C#][/code]
 /// <summary>
/// 执行cmd命令函数
/// </summary>
/// <param name="command">cmd命令字符串</param>
public void Cmd(string command, string command1)
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardInput = true;
process.Start();

process.StandardInput.WriteLine(command);
process.StandardInput.WriteLine(command1);
process.StandardInput.AutoFlush = true;
process.StandardInput.WriteLine("exit");
StreamReader reader = process.StandardOutput;//截取输出流

string output = reader.ReadLine();//每次读取一行

while (!reader.EndOfStream)
{
PrintThrendInfo(output);
output = reader.ReadLine();
}
reader.Close();
process.WaitForExit();
}

private void BTN_Install_Click(object sender, EventArgs e)
{
LBL_ServiceStatus.Text = "服务安装中...";
Application.DoEvents();
BTN_Install.Enabled = false;
string command = @"%systemroot%\microsoft.net\framework\v2.0.50727\InstallUtil.exe EDI.FileCreatWatcherSVC.exe";
string commandStr = @"cd " + AppDomain.CurrentDomain.BaseDirectory;
Cmd(commandStr, command);

}
private void BTN_Uninstall_Click(object sender, EventArgs e)
{
BTN_Uninstall.Enabled = false;
BTN_StartService.Enabled = false;
LBL_ServiceStatus.Text = "服务卸载中...";
Application.DoEvents();

string command = @"%systemroot%\microsoft.net\framework\v2.0.50727\InstallUtil.exe /u EDI.FileCreatWatcherSVC.exe";
string commandStr = @"cd " + AppDomain.CurrentDomain.BaseDirectory;
Cmd(commandStr, command);

}


//赶紧散分吧