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

Wednesday, August 5, 2009

How to Restart the Window Services using VB.Net?

Imports System.ServiceProcess.ServiceController

Function RestartService() As Boolean
Try
Dim controller As New ServiceProcess.ServiceController
controller.MachineName = "."
controller.ServiceName = "MSSQL$SQLEXPRESS"
Dim status As String = controller.Status.ToString
If status = "Running" Then
controller.Stop()
End If
controller.Start()
Return True
Catch ex As Exception
Return False
End Try
End Function

Friday, July 31, 2009

How to Install/Uninstall the Window Service?

Build the service By Build--> Srevice Name

After that Get the service Path that is in Bin Folder.

open start--> visual studio 2005-->visual studio tools--> visual studio command prompt

in that

For Installation
C:\Program files\Microsoft Visual Studio 8\VC\>installutil

Example:
C:\Program files\Microsoft Visual Studio 8\VC\>installutil -i d:Testservice\debug\testservice.exe


For Uninstalltion
C:\Program files\Microsoft Visual Studio 8\VC\>installutil /u

Example:
C:\Program files\Microsoft Visual Studio 8\VC\>installutil /u d:Testservice\debug\testservice.exe

Monday, February 9, 2009

Creating windows service using C#.Net?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using System.Data.SqlClient;


namespace TestService
{
public partial class Wind_Service : ServiceBase
{
public Wind_Service()
{
InitializeComponent();
}



public System.Threading.Timer stateTimer;
public TimerCallback delegateTimer;
SqlConnection con = new SqlConnection("MultipleActiveResultSets=True;Server=" + ".\\SQLEXPRESS;DataBase=db;Integrated Security=SSPI;");
SqlCommand cmd;
SqlDataAdapter adp = new SqlDataAdapter();



#region On Service Start
protected override void OnStart(string[] args)
{
delegateTimer = new TimerCallback(performAction);
stateTimer = new Timer(delegateTimer, null, 0, (1000 * 60 * 1)); //One second = 1000 miliseconds)
EventLog.WriteEntry("Service Exactly Started at : " + DateTime.Now.ToString());
}
#endregion

#region Body of the Code
public void performAction(object sender)
{
try
{
//Body of the code
}
catch (Exception ex)
{
EventLog.WriteEntry("Service having error : " + ex.Message);
}
}
#endregion


#region On Service Stop
protected override void OnStop()
{
EventLog.WriteEntry("Service Stopped Successfully at : " + DateTime.Now.ToString());
}
#endregion

}
}
 
Feedback Form