Showing posts with label Windows Service. Show all posts
Showing posts with label Windows Service. Show all posts

Friday, July 20, 2012

How To: Delete/Remove Services In Windows

Users can usually uninstall applications from their computers quite easily, however the same cannot be said for Windows services, of course you can disable a service, but the entry for it may still remain.

If you are looking for a way to completely delete a service from Windows here is how we can do this.

Open a command prompt, by going to Start > Run and type in cmd without the quotes and hit the Enter key.

Once a command prompt has opened up, type the command sc delete service name without the quotes

image

Once a service has been deleted you should see a message saying [SC] DeleteService SUCCESS, this should mean that the service has been deleted, to ensure that, just click on the refresh button in the services.msc window and confirm that the service has been deleted.

Note: You should always delete services in safe mode, just in case it causes you any problem, you may also want to create system restore points, just in case something goes wrong. But If you are a developer and its your own service then you don’t need to do this since you know about your service how it works.  Smile

Friday, June 25, 2010

How to: Running Windows service at a specified time period.

I am writing an Notification service, for that i need to send reminders based on a time period. This is how I did. Here i am Configuring notification time and service interval time in app.config. For me, notification time is the time when to execute the logic and service interval time will tell the timer when to stop and start. If we want we can make this data driven as well. I have added a timer control. Here is the sample code snippet here for this.

public partial class Service1 : ServiceBase
{
    private System.Timers.Timer timer = null;
    private NotificationClass nc = new NotificationClass();
    private string notificationTime = ConfigurationManager.AppSettings["notificationTime"];
    // Default time to start and stop the timer.
    private string serviceInterval = ConfigurationManager.AppSettings["serviceInterval"];
    public Service1()
    {
        InitializeComponent();
        timer = new System.Timers.Timer(Convert.ToDouble(serviceInterval));
        timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
    }
    private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
        // Compare this notification time with your time...
        if (DateTime.Now.ToShortTimeString() == notificationTime)
        {
            this.timer.Enabled = false;
            this.timer.AutoReset = false;
            // Do the logic
            nc.BirthdayReminder();
            this.timer.Start();
        }
    }
    protected override void OnStart(string[] args)
    {
        // TODO: Add code here to start your service.
        timer.AutoReset = true;
        timer.Enabled = true;
        timer.Start();
    }
    protected override void OnStop()
    {
        // TODO: Add code here to perform any tear-down necessary to stop your service.
        timer.AutoReset = false;
        timer.Enabled = false;
    }
}