I am creating simple windows services that calls my batch file,Now i want to stop or terminate the batch file by stopping it to the services.msc,my services stop but the batch file is still active in the background.how can i terminate the batch file in the background i will stop my services.
Thank you in advance.
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
namespace Myservices
{
public partial class Myservices: ServiceBase
{
private ProcessStartInfo processListener;
Process p;
public Myservices()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
processListener = new ProcessStartInfo{
CreateNoWindow = true,
UseShellExecute = false,
FileName = "cmd.exe",
Arguments = string.Format("/C \"{0}\"", "C:\\myservices\\servceupdate.bat"),
WindowStyle = ProcessWindowStyle.Hidden,
RedirectStandardOutput = true,
RedirectStandardError = true,
ErrorDialog = false
};
p=Process.Start(processListener);
}
protected override void OnStop()
{
p.Close();//Here my batch file did not terminate.
}
}