我正在尝试从远程机器重新启动服务。这是我的代码。问题是我需要输入,startinfo.filename = "sc.exe"
因为我输入"start /wait sc"
这会导致错误。这是我的代码,任何想法。此外,如果有人知道如何在运行后保持 cmd 窗口打开,那么我可以看到运行的代码会很棒。
string strCommandStop1;
string strCommandStop2;
string strCommandStart1;
string strCommandStart2;
string strServer = "\\" + txtServerName.Text;
string strDb1 = "SqlAgent$" + txtInsName.Text;
string strDb2 = "MSSQL$" + txtInsName.Text;
strCommandStop1 = @"start /wait sc " + strServer + " Stop " + strDb1;
strCommandStop2 = @"start /wait sc " + strServer + " Stop " + strDb2;
strCommandStart1 = @"start /wait sc " + strServer + " Start " + strDb2;
strCommandStart2 = @"start /wait sc " + strServer + " Start " + strDb1;
try
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = true;
startInfo.Arguments = strCommandStop1;
startInfo.Arguments = strCommandStop2;
startInfo.Arguments = strCommandStart1;
startInfo.Arguments = strCommandStart2;
startInfo .FileName = "sc.exe";
Process.Start(startInfo);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}