Home > Microsoft .Net Development Tips > Microsoft Office Development > Writing a Windows service
Win Development Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

MICROSOFT OFFICE DEVELOPMENT

Writing a Windows service


Manish Mehta
02.28.2003
Rating: -3.71- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


Let other users know how useful this tip is by rating it below. Got a tip or code of your own you'd like to share? Submit it here!


With .NET, developing a Windows Service is a piece of cake. VS.NET has a project template for creating Windows service. In this tip, I will walk you through the steps of creating a simple Windows service.

Step 1: Developing a service

From VS.NET File menu -> New -> Project, select the Windows Service project template.

WindowsService1
[IMAGE]

The code for the WinService is pretty straight forward, there are events like:

OnStart
OnStop
OnPause
OnContinue

And other events to get the most out of the Windows service.

Write the code in the respective event handlers, but remember a service will be running in the background. Don't write any kind of code which involves messages boxes, forms and other model UI elements.

Step 2: Building the service

From t


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
Microsoft Office Development
Downloadable MSDN library released for VS 2008 SP 1
Check the MSDN Virtual Labs for regular, compelling new content
Windows XP SP3 pack includes new XML parser, enhanced IP security
Book excerpt: Building personalized solutions in SharePoint 2007
Book excerpt: Building document management solutions in SharePoint 2007
XAML as an everywhere presentation format
Where are the Visual Studio 2008 Tools for Office?
ClickOnce: Automated smart client deployment
Book excerpt: SharePoint 2007 and content types
Update desktops automatically using the AppUpdater component

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary


he design mode of the Windows service, right click, and from the menu select "AddInstaller," This will add two components on the designer, which will be used to install the service in the Service Control manager. Right click on the serviceprocessinstaller1 component and set the Account Property to "LocalSystem." And build the solution.

Step 3: Installing the service

After building the service, the next step is to install the service. This is done using the InstallUtil tool provided by Microsoft. Go to the bin folder of the WinService project in your HDD. You should find WindowsService1.exe. Use the installutil.exe tool as InstallUtil WindowsService1.exe. This will install the WindowsService1 as a service.

If you open the Service manager, you will be able to see Service1 in the list of services. You can manipulate the service as any other service by starting, stopping, setting the properties, etc.

That's it folks.


Source: DotNetExtreme.com

Rate this Tip
To rate tips, you must be a member of SearchWinDevelopment.com.
Register now to start rating these tips. Log in if you are already a member.




DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Database Programming Solutions - .NET XML, Visual Studio LINQ, ORM .NET
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2000 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts