August 17th, 2010

You are currently browsing the articles from Information City written on August 17th, 2010.

VS2008 (VB.NET) : Creating a windows services

Here’s a rough detail on the steps required to create a new windows services:

1. Create new window services project
2. In the toolbox, right click -> select “choose item”
3. Add Timer from namespace “system.timers”
4. Drag and drop into the Service1.vb designer window of the timer object that you have just added.
5. Double click the Timer object, add below codes into Timer1_Elapsed sub codes:
'create a new event log
'Check if the Event Log Exists
If Not Diagnostics.EventLog.SourceExists("Service") Then
Diagnostics.EventLog.WriteEntry("Service", "Service_Log")
' Create Log
End If
'Write to the Log
Dim MyLog As New EventLog()
MyLog.Source = "Service"
Diagnostics.EventLog.WriteEntry(MyLog.Source, "First Web Service Application running", EventLogEntryType.Information)
'EventLog.WriteEntry("Timer1 is Beginning")

6. Activate the timer by adding below code onto the OnStart sub code:
Timer1.Enabled = True
7. Right click the designer window of the Service1.vb and select “add installer”
8. In the designer window of the newly added ProjectInstaller.vb interface, select the ServiceProcessInstaller1 object. Change the Account property value to “LocalSystem”.
9. Select the ServiceInstaller1 object and change the “DisplayName” value to the value that you wish to display in the Services listing later. The “StartType” value provide the flexibility to automatically or manually start up the services upon windows restart.
10. Once done, proceed to Build -> Project
11. Adjourn to the Release folder and make sure the executable file is present.
12. Open up command prompt, execute the below statement:
For installation of the windows services.
Installutil executable.exe
To uninstall:
Installutil executable.exe /U
13. Proceed to the Services listing, search for the windows service name that you have provided in the “DisplayName” of step #9, and right click to start it.
14. Proceed to Eventlog, Application section and you will see the latest entry of log created by the application has been added.

Feel free to leave your comments and queries should there be any!

Written by admin on August 17th, 2010 with no comments.
Read more articles on Knowledge Base and Programming.