<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>PROGRAMMER DESK &#187; Windows Services</title>
	<atom:link href="http://vinayhatwal.wordpress.com/category/net/windows-services-net/feed/" rel="self" type="application/rss+xml" />
	<link>http://vinayhatwal.wordpress.com</link>
	<description>Accept Changes To Develop Good Solutions</description>
	<lastBuildDate>Sun, 02 Aug 2009 10:34:20 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='vinayhatwal.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/fddfa1cd68a112c3fb6eca04033658e3?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>PROGRAMMER DESK &#187; Windows Services</title>
		<link>http://vinayhatwal.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://vinayhatwal.wordpress.com/osd.xml" title="PROGRAMMER DESK" />
		<item>
		<title>Windows Services</title>
		<link>http://vinayhatwal.wordpress.com/2009/04/10/windows-services/</link>
		<comments>http://vinayhatwal.wordpress.com/2009/04/10/windows-services/#comments</comments>
		<pubDate>Fri, 10 Apr 2009 07:58:38 +0000</pubDate>
		<dc:creator>vinayhatwal</dc:creator>
				<category><![CDATA[Windows Services]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[services]]></category>
		<category><![CDATA[Vinayhatwal]]></category>
		<category><![CDATA[windows services]]></category>

		<guid isPermaLink="false">http://vinayhatwal.wordpress.com/?p=118</guid>
		<description><![CDATA[Windows Services


By: Vinay Hatwal
Dated: Apr 10, 2009 
Level: Beginner
 
The idea of using Windows services came into my mind when I was working on Finger Print Attendance System for Bajaj Capital Ltd. This system was going to be used by all the branches of the company. So I wanted to synchronize the attendance of the employees [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vinayhatwal.wordpress.com&blog=4320862&post=118&subd=vinayhatwal&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:center;"><strong>Windows Services</strong></p>
<p style="text-align:left;">
<p class="MsoNormal">
<p class="MsoNormal"><em>By: Vinay Hatwal</em></p>
<p class="MsoNormal"><em>Dated: Apr 10, 2009<span> </span></em></p>
<p class="MsoNormal"><em>Level: Beginner</em></p>
<p class="MsoNormal"> </p>
<p class="MsoNormal" style="text-align:justify;">The idea of using Windows services came into my mind when I was working on Finger Print Attendance System for Bajaj Capital Ltd. This system was going to be used by all the branches of the company. So I wanted to synchronize the attendance of the employees of each branch with our company’s ERP system. So that, I decided to develop windows services for the same purpose. There was one issue in real time synchronization of attendance with the Head Office.<span> </span>The issue was slow internet connection and no internet connectivity available all the time. So the solution was to send the attendance when internet is connected not on the time of attendance punching. So the solution was WINDOWS SERVICES.</p>
<p class="MsoNormal" style="text-align:justify;">
<p class="MsoNormal" style="text-align:justify;">In this article I will explain how to make Windows Services by using c#.net.</p>
<p class="MsoNormal" style="text-align:justify;">
<p class="MsoNormal" style="text-align:justify;"><strong>Windows services</strong> are long running executable file developed for running in background as long a windows is running. These executables run in the background and there is no any requirement for the user interaction. They run in the background so that there is no need to take graphical interface in the Windows Services. You can think about UNIX Daemon if u r familiar with the UNIX environment. On the Windows the same concept is Windows Services. Windows Services can be configured to run automatically when Windows is booted. They can also be configured to run on Local machine, single user account, and also on Network.</p>
<p class="MsoNormal" style="text-align:justify;">
<p class="MsoNormal" style="text-align:justify;">You can find windows services in your local machine on</p>
<p class="MsoNormal" style="text-align:justify;">Start-&gt; Control Panel -&gt; Administrative Tools -&gt; Services</p>
<p class="MsoNormal" style="text-align:justify;"><span style="font-size:12pt;font-family:&quot;">These services looks like this—</span></p>
<p style="text-align:center;">
<p style="text-align:left;">
<div style="text-align:left;"><strong></strong></div>
<p><strong></p>
<div id="attachment_121" class="wp-caption aligncenter" style="width: 710px"><strong><img class="size-full wp-image-121 " title="111" src="http://vinayhatwal.files.wordpress.com/2009/04/111.jpg?w=700&#038;h=768" alt="Windows Service Browser" width="700" height="768" /></strong><p class="wp-caption-text">Windows Service Browser</p></div>
<p> </p>
<p></strong></p>
<p style="text-align:left;">
<p style="text-align:left;">
<p class="MsoNormal" style="text-align:justify;">By using windows service you can use databases, text files, and all shareable resources with it etc.</p>
<p class="MsoNormal" style="text-align:justify;">
<p class="MsoNormal" style="text-align:justify;">To create Windows Services in .net (I am creating in .net 2.0)</p>
<p class="MsoNormal" style="text-align:justify;">
<p class="MsoNormal" style="text-align:justify;">
<p class="MsoNormal" style="text-align:justify;"><strong><span style="font-size:14pt;">Creating Windows Services</span></strong></p>
<p class="MsoNormal" style="text-align:justify;">
<p class="MsoNormal" style="margin-left:.5in;text-align:justify;text-indent:-.25in;">&lt;!&#8211;[if !supportLists]&#8211;&gt;<span>1)<span style="font-family:&quot;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span>&lt;!&#8211;[endif]&#8211;&gt;To create windows services, go to File menu and then select New Project, then select Windows Service. You will see the dialog box shown below. Name the project – MyWindowService.</p>
<p><img class="aligncenter size-full wp-image-122" title="12" src="http://vinayhatwal.files.wordpress.com/2009/04/12.jpg?w=680&#038;h=494" alt="12" width="680" height="494" /></p>
<p class="MsoNormal" style="text-align:justify;"><span style="font-size:11pt;">2) After clicking on OK you will see the following. Change the name of the service from Service1.cs to MyService.cs. </span></p>
<p><img class="aligncenter size-full wp-image-123" title="2" src="http://vinayhatwal.files.wordpress.com/2009/04/2.jpg?w=1024&#038;h=768" alt="2" width="1024" height="768" /></p>
<p class="MsoNormal" style="text-align:justify;"><span style="font-size:11pt;">3) Now go to in on the properties on the MyService and change the property Service Name to MyService.</span></p>
<p class="MsoNormal" style="text-align:justify;"> </p>
<p class="MsoNormal" style="text-align:justify;"> </p>
<p class="MsoNormal" style="text-align:justify;"><span style="font-size:11pt;">4) Do right click on the MyService design view and select <strong>View Code</strong> option from the context menu. You can see two overrided methods in the window OnStart() and OnStop(). </span></p>
<p class="MsoNormal" style="text-align:justify;"> </p>
<p class="MsoNormal" style="text-align:justify;"> </p>
<p class="MsoNormal" style="text-align:justify;"><span style="font-size:11pt;">These are the members of the ServiceBase class and inheritted by the MyService Class. There are some more members also present in the ServiceBase class like OnContinue(), OnPause() etc. but I am just describing about these two only.<span> </span></span></p>
<p class="MsoNormal" style="text-align:justify;"> </p>
<p class="MsoNormal" style="text-align:justify;"><span style="font-size:11pt;">The idea of using windows service is only behind these to methods. Any work u want to perform on the sharable resources, you can write code for that in the OnStart() method. I have just put Beep () here. It will give the beep sound on starting the Window Service. And just 2 beep on Stoping it. You can see in the coding below.</span></p>
<p><img class="aligncenter size-full wp-image-124" title="3" src="http://vinayhatwal.files.wordpress.com/2009/04/3.jpg?w=1024&#038;h=768" alt="3" width="1024" height="768" /></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify;text-indent:-.25in;">&lt;!&#8211;[if !supportLists]&#8211;&gt;<span style="font-size:11pt;"><span>5)<span style="font-family:&quot;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span></span>&lt;!&#8211;[endif]&#8211;&gt;<span style="font-size:11pt;">to install this Windows Service on the local system you need to add installers in your Service. Just right click on the Service Design window and then select <strong>Add Installer.</strong></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify;text-indent:-.25in;">
<p class="MsoNormal" style="margin-left:.5in;text-align:justify;text-indent:-.25in;">
<p class="MsoNormal" style="margin-left:.5in;text-align:justify;text-indent:-.25in;">&lt;!&#8211;[if !supportLists]&#8211;&gt;<span style="font-size:11pt;"><span>6)<span style="font-family:&quot;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span></span>&lt;!&#8211;[endif]&#8211;&gt;<span style="font-size:11pt;">Project Installer will automatically be added in your solution, name ProjectInstaller.sc. and you can also find two component in it </span></p>
<p class="MsoNormal" style="margin-left:1in;text-align:justify;text-indent:-.25in;">&lt;!&#8211;[if !supportLists]&#8211;&gt;<span style="font-size:11pt;"><span>a.<span style="font-family:&quot;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span></span>&lt;!&#8211;[endif]&#8211;&gt;<span style="font-size:11pt;">serviceProcessInstaller1</span></p>
<p class="MsoNormal" style="margin-left:1in;text-align:justify;text-indent:-.25in;">&lt;!&#8211;[if !supportLists]&#8211;&gt;<span style="font-size:11pt;"><span>b.<span style="font-family:&quot;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span></span>&lt;!&#8211;[endif]&#8211;&gt;<span style="font-size:11pt;">serviceInstaller1</span></p>
<p class="MsoNormal" style="text-align:justify;"> </p>
<p class="MsoNormal" style="text-align:justify;"> </p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify;text-indent:-.25in;">&lt;!&#8211;[if !supportLists]&#8211;&gt;<span style="font-size:11pt;"><span>7)<span style="font-family:&quot;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span></span>&lt;!&#8211;[endif]&#8211;&gt;<span style="font-size:11pt;">You can now decide how your Windows Process will be display, you can set the account for your service on which it will be running, and you can give the Display Service Name, Description and the start type of the service like Automat, Manual, or Disabled. For doing all these you can follow these steps</span></p>
<p class="MsoNormal" style="margin-left:1in;text-align:justify;text-indent:-.25in;">&lt;!&#8211;[if !supportLists]&#8211;&gt;<span style="font-size:11pt;"><span>a.<span style="font-family:&quot;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span></span>&lt;!&#8211;[endif]&#8211;&gt;<span style="font-size:11pt;">Go to on the properties of <strong>serviceProcessInstaller1</strong>, and set <strong>Account</strong><span> </span>property to Local System, so that it would be sharable to all users.</span></p>
<p class="MsoNormal" style="margin-left:1in;text-align:justify;text-indent:-.25in;">&lt;!&#8211;[if !supportLists]&#8211;&gt;<span style="font-size:11pt;"><span>b.<span style="font-family:&quot;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span></span>&lt;!&#8211;[endif]&#8211;&gt;<span style="font-size:11pt;">Now go to on the properties of <strong>serviceInstaller1, </strong>and<strong> </strong>ser <strong>Description</strong> as u like and set <strong>Display Name</strong> as u want to display in the Services Console, and now set<span> </span><strong>StartType</strong> to <strong>Automatic</strong> so that the service can be run on the starting of the Windows operation system.</span></p>
<p class="MsoNormal" style="margin-left:.75in;text-align:justify;"> </p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify;text-indent:-.25in;">&lt;!&#8211;[if !supportLists]&#8211;&gt;<span style="font-size:11pt;"><span> <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> <span style="font-family:&quot;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span></span>&lt;!&#8211;[endif]&#8211;&gt;<span style="font-size:11pt;">After doing all the configuration just press F6 for building the solution. Now Your Window Service is ready to use.</span></p>
<p class="MsoNormal" style="margin-left:.25in;text-align:justify;"> </p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify;text-indent:-.25in;">&lt;!&#8211;[if !supportLists]&#8211;&gt;<span style="font-size:11pt;"><span>9)<span style="font-family:&quot;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span></span>&lt;!&#8211;[endif]&#8211;&gt;<span style="font-size:11pt;">Now for using it u have to install this service on your local machine. You can do this by using the instalUtill.exe utility provided by .net framework to install this service on your machine.</span></p>
<p class="MsoNormal" style="text-align:justify;"> </p>
<p class="MsoNormal" style="margin-left:.25in;text-align:justify;"><span style="font-size:11pt;">Now take the executable of this service and jus copy it into your system32 directory.</span></p>
<p class="MsoNormal" style="margin-left:.25in;text-align:justify;"> </p>
<p class="MsoNormal" style="margin-left:.25in;text-align:justify;"><span style="font-size:11pt;">Go to your application path where your project is running, and go to the bin\debug directory then copy MyWindowServices.exe and paste it into syetem32.</span></p>
<p class="MsoNormal" style="margin-left:.25in;text-align:justify;"> </p>
<p class="MsoNormal" style="margin-left:.25in;text-align:justify;"> </p>
<p class="MsoNormal" style="margin-left:.25in;text-align:justify;"><span style="font-size:11pt;">Now go to on the <strong>Visual Studio 2005 Command Prompt</strong> and type the following for installing the newly developed Window Service–</span></p>
<p class="MsoNormal" style="margin-left:.25in;text-align:justify;"> </p>
<p class="MsoNormal" style="margin-left:.25in;text-align:justify;"><strong><span style="font-size:11pt;">C:\&gt; installutil c:\windows\system32\</span> </strong><strong><span style="font-size:11pt;">MyWindowServices.exe</span></strong></p>
<p class="MsoNormal" style="margin-left:.25in;text-align:justify;">
<p class="MsoNormal" style="margin-left:.25in;text-align:justify;"><strong><span style="font-size:11pt;"><img class="aligncenter size-full wp-image-125" title="4" src="http://vinayhatwal.files.wordpress.com/2009/04/4.jpg?w=667&#038;h=503" alt="4" width="667" height="503" /></span></strong></p>
<p class="MsoNormal" style="margin-left:.25in;text-align:justify;">
<p class="MsoNormal" style="margin-left:.25in;text-align:justify;">
<p class="MsoNormal" style="margin-left:.25in;text-align:justify;"><span style="font-size:11pt;">To uninstall use –</span></p>
<p class="MsoNormal" style="margin-left:.25in;text-align:justify;"> </p>
<p class="MsoNormal" style="margin-left:.25in;text-align:justify;"><strong><span style="font-size:11pt;">C:\&gt; installutil /u c:\windows\system32\</span> </strong><strong><span style="font-size:11pt;">MyWindowServices.exe</span></strong></p>
<p class="MsoNormal" style="margin-left:.25in;text-align:justify;"> </p>
<p class="MsoNormal" style="margin-left:.25in;text-align:justify;"> </p>
<p><span style="font-size:11pt;font-family:&quot;">You can see your service in the service console like </span></p>
<p><span style="font-size:11pt;font-family:&quot;"><img class="aligncenter size-full wp-image-126" title="5" src="http://vinayhatwal.files.wordpress.com/2009/04/5.jpg?w=1024&#038;h=768" alt="5" width="1024" height="768" /></span></p>
<p class="MsoNormal" style="margin-left:.25in;text-align:justify;"><span style="font-size:11pt;">Now just do right click on it and the start. You will listen one beep on starting and two beep on stopping the Windows Service.</span></p>
<p class="MsoNormal" style="margin-left:.25in;text-align:justify;"> </p>
<p class="MsoNormal" style="margin-left:.25in;text-align:justify;"><span style="font-size:11pt;">So friends. Enjoy the Window Services, hope your will learn by this article. Hope you will be enjoying after creation the windows service.</span></p>
<p class="MsoNormal" style="margin-left:.25in;text-align:justify;"> </p>
<p class="MsoNormal" style="margin-left:.25in;text-align:justify;"><span style="font-size:11pt;">I am always waiting for your comments and suggestion so that I can improve my articles.<span> </span></span></p>
<p class="MsoNormal" style="margin-left:.25in;text-align:justify;"> </p>
<p class="MsoNormal" style="margin-left:.25in;text-align:justify;"><span style="font-size:11pt;">Again<span> </span>Coming Soon…………………….</span></p>
<p class="MsoNormal" style="margin-left:.25in;text-align:justify;"> </p>
<p class="MsoNormal" style="margin-left:.25in;text-align:justify;"> </p>
<p class="MsoNormal" style="margin-left:.25in;text-align:justify;"> </p>
<p class="MsoNormal" style="margin-left:.25in;text-align:justify;"><strong><span style="font-size:11pt;">Vinay Hatwal</span></strong></p>
Posted in Windows Services Tagged: .Net, services, Vinayhatwal, windows services <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vinayhatwal.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vinayhatwal.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vinayhatwal.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vinayhatwal.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vinayhatwal.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vinayhatwal.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vinayhatwal.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vinayhatwal.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vinayhatwal.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vinayhatwal.wordpress.com/118/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vinayhatwal.wordpress.com&blog=4320862&post=118&subd=vinayhatwal&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://vinayhatwal.wordpress.com/2009/04/10/windows-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/30134ff30180ffc15825d15c005dbce5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vinayhatwal</media:title>
		</media:content>

		<media:content url="http://vinayhatwal.files.wordpress.com/2009/04/111.jpg" medium="image">
			<media:title type="html">111</media:title>
		</media:content>

		<media:content url="http://vinayhatwal.files.wordpress.com/2009/04/12.jpg" medium="image">
			<media:title type="html">12</media:title>
		</media:content>

		<media:content url="http://vinayhatwal.files.wordpress.com/2009/04/2.jpg" medium="image">
			<media:title type="html">2</media:title>
		</media:content>

		<media:content url="http://vinayhatwal.files.wordpress.com/2009/04/3.jpg" medium="image">
			<media:title type="html">3</media:title>
		</media:content>

		<media:content url="http://vinayhatwal.files.wordpress.com/2009/04/4.jpg" medium="image">
			<media:title type="html">4</media:title>
		</media:content>

		<media:content url="http://vinayhatwal.files.wordpress.com/2009/04/5.jpg" medium="image">
			<media:title type="html">5</media:title>
		</media:content>
	</item>
	</channel>
</rss>