public string ExecuteCommand(string cmd, string IP)
{
try
{
string filename = "";
string args = "";
int resultsadom = 0;
filename = "cmd.exe";
args = "/C " + cmd;
using (Process compiler = new Process())
{
compiler.StartInfo.FileName = filename;
compiler.StartInfo.Arguments = args;
compiler.StartInfo.UseShellExecute = false;
compiler.StartInfo.RedirectStandardOutput = true;
compiler.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
compiler.Start();
string output = compiler.StandardOutput.ReadToEnd();
compiler.WaitForExit();
if (output.Contains("SERVICE_N"))
output = "Success";
string clean = output.Replace("\n", "").Replace("\r", "");
return $"{IP} : {clean} \n";
}
}
catch (Exception objException)
{
return $"Message Error Command : {(objException.Message)} \n";
}