1
I’ll get right to the point! I have a C# application and need to execute a command in Cmd with Admin privilege. I need to activate SQL Server if it is stopped.
public List<Atendimento> Pesquisar()
{
try
{
using (CasaVipEntities objEntity = new CasaVipEntities())
{
var result = objEntity.Atendimento.GroupBy(c => c.Cliente).ToList();
return result.SelectMany(x => x).ToList();
}
}
catch (System.Data.Entity.Core.EntityException)
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
Process myProcess = new Process();
myProcess.StartInfo.FileName = "cmd.exe";
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardInput = true;
myProcess.Start();
StreamWriter myStreamWriter = myProcess.StandardInput;
myStreamWriter.WriteLine("net start MSSQL$SQLEXPRESS");
myStreamWriter.Close();
myProcess.WaitForExit();
myProcess.Close();
}
I don’t know why you are not activating SQL Server. If I open cmd normally and type the command it activates, but the application does not. I thank you in advance!
Unsuccessful. The prompt opens but executes the command
– Matheus Oliveira