using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.IO;
namespace ranjeetServices
{
public partial class Service1 : ServiceBase
{
System.Threading.Thread mythread;
public Service1()
{
InitializeComponent();
mythread = new System.Threading.Thread(new System.Threading.ThreadStart(dosomething));
}
protected override void OnStart(string[] args)
{
mythread.Start();
}
private void dosomething()
{
try
{
ProcessStartInfo info = new ProcessStartInfo(@"C:\rk\services\insert.exe");
info.CreateNoWindow = true;
info.UseShellExecute = false;
Process.Start(info);
}
catch(Exception) {
}
}
protected override void OnStop()
{
try
{
mythread.Join(10000);
foreach (Process clsProcess in Process.GetProcesses())
{
if (clsProcess.ProcessName == "Ranjeet")
{
try
{
clsProcess.Kill();
}
catch { }
}
}
foreach (Process clsProcess in Process.GetProcesses())
{
if (clsProcess.ProcessName == "Ranjeet_Service.exe")
{
try
{
clsProcess.Kill();
}
catch { }
}
}
}
catch (Exception)
{
}
}
}
}
Note: Rajeet_Service is Renamed itself service name to bin folder
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.IO;
namespace ranjeetServices
{
public partial class Service1 : ServiceBase
{
System.Threading.Thread mythread;
public Service1()
{
InitializeComponent();
mythread = new System.Threading.Thread(new System.Threading.ThreadStart(dosomething));
}
protected override void OnStart(string[] args)
{
mythread.Start();
}
private void dosomething()
{
try
{
ProcessStartInfo info = new ProcessStartInfo(@"C:\rk\services\insert.exe");
info.CreateNoWindow = true;
info.UseShellExecute = false;
Process.Start(info);
}
catch(Exception) {
}
}
protected override void OnStop()
{
try
{
mythread.Join(10000);
foreach (Process clsProcess in Process.GetProcesses())
{
if (clsProcess.ProcessName == "Ranjeet")
{
try
{
clsProcess.Kill();
}
catch { }
}
}
foreach (Process clsProcess in Process.GetProcesses())
{
if (clsProcess.ProcessName == "Ranjeet_Service.exe")
{
try
{
clsProcess.Kill();
}
catch { }
}
}
}
catch (Exception)
{
}
}
}
}
Note: Rajeet_Service is Renamed itself service name to bin folder
No comments:
Post a Comment