protected override void OnStart(string[] args)
{
Timer T1 = new Timer();
T1.Interval = (1000);
T1.AutoReset = true;
T1.Enabled = true;
T1.Start();
T1.Elapsed += new System.Timers.ElapsedEventHandler(T1_Elapsed);
if (!File.Exists(@"F:\KillLog.txt"))
{
File.Create(@"F:\KillLog.txt");
}
using (StreamWriter sw = new StreamWriter(@"F:\KillLog.txt", true))
{
sw.WriteLine("Killing process Service starts at : {0}", DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt"));
}
timer1.Enabled = true;
}
protected override void OnStop()
{
Timer T1 = new Timer();
T1.Interval = (1000);
T1.AutoReset = true;
T1.Enabled = true;
T1.Start();
T1.Elapsed += new System.Timers.ElapsedEventHandler(T1_Elapsed);
using (StreamWriter sw = new StreamWriter(@"F:\KillLog.txt", true))
{
sw.WriteLine("Killing process Service stops : {0}", DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt"));
}
timer1.Enabled = false;
}
private void timer1_Tick(object sender, EventArgs e)
{
using (StreamWriter sw = new StreamWriter(@"F:\KillLog.txt", true))
{
sw.WriteLine("Checking Process: {0}", DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt"));
}
Process[] runingProcess = Process.GetProcesses();
for (int i = 0; i < runingProcess.Length; i++)
{
if (runingProcess[i].ProcessName == "mspaint")
{
runingProcess[i].Kill();
}
}
}
private void T1_Elapsed(object sender, EventArgs e)
{
using (StreamWriter sw = new StreamWriter(@"F:\KillLog.txt", true))
{
sw.WriteLine("Checking Process: {0}", DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt"));
}
Process[] runingProcess = Process.GetProcesses();
for (int i = 0; i < runingProcess.Length; i++)
{
if (runingProcess[i].ProcessName == "mspaint")
{
runingProcess[i].Kill();
}
}
}