1. In a command window, I would type: sc config "Bonjour Service" start= "manual"
2. How do I do this from within a C# program?
3. Do I need to stop anything when this has finished? (In the command window it sim,ply stops after it has processed my request).
THANKS!!!
JasonPosted Jul 31, 2009, 7:57 AM
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);
}
Any thoughts on what I could change to make this work. I'm trying to restart a service from a remote machine on the network.
Thanks
Robert BonePosted May 21, 2009, 11:45 AM
nickPosted May 21, 2009, 8:45 AM
try to use the proccesStartInfo:
like this:
Process proc = new Process(); //call new Process
ProcessStartInfo info = new ProcessStartInfo(); //call new ProcessStartInfo
info.Arguments = "config \"Bonjour Service\" start= \"manual\""; //set the arguments
info.FileName = "sc.exe"; //set the file name (location)
proc.StartInfo = info; //put the StartInfo into the Procces method
proc.Start(); //Start the procces (sc.exe with the arguments)
proc.WaitForExit(); //waits till the procces is done
i hope this helped
dont forget : using System.Diagnostics;