Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Creating Windows Services in .NET  : Page 4

When you need to run unattended applications that can monitor directories and log events, don't even think about writing a desktop application—write a Windows service instead.


advertisement
Unlike other types of .NET applications, you must explicitly install a Windows service application on the target system. Fortunately, VS.NET makes this task quite easy. For service projects, the IDE displays a link in the Properties window titled "Add Installer." When you click the link VS.NET adds the necessary installer classes to your project, as part of a separate module. You can set various properties, the most important of which is the Account property of the ServiceProcessInstaller class. The Account property determines the security context under which the service will run.

The choices are:

  • LocalService: The service has extensive local privileges and presents the computer's credentials to remote servers.
  • LocalSystem: The service has limited local privileges and presents anonymous credentials to remote servers.
  • NetworkService: The service has limited local privileges and presents the computer's credentials to remote servers.
  • User: You specify a local or network account, and provide the username and password either as properties or during installation. The service uses the security context of the specified user account.
To install a service you must compile the service project into an exe file, and then run the utility program InstallUtil.exe (installed with the .NET Framework). At a command prompt enter the command:

installutil servicename.exe

You must provide the complete path to the service's exe file. The InstallUtil application installs the specified service. will be installed. After installing the new service, you can find it in the Services window of the Computer Management applet. (You can use the InstallUtil program to uninstall a service as well.)

Windows services are an often overlooked type of application. They are relatively specialized, but for certain type of tasks, usually in the administrative category, they fit the bill perfectly. The .NET Framework provides classes designed specifically for creating and controlling Windows service applications. Given that the required programming is relatively simple, you should take advantage of Windows services.



Peter G. Aitken has been writing about computers and programming for over 10 years, with some 30 books and hundreds of articles to his credit. Recent book titles include Developing Office Solutions With Office 2000 Components and VBA, Windows Script Host, and the soon to be published XML the Microsoft Way. He is a regular contributor to OfficePro magazine, and for several years was a contributing editor for Visual Developer Magazine where he wrote the popular Visual Basic column. Peter is the proprietor of PGA Consulting, providing custom application and Internet development to business, academia, and government since 1994. You can reach him at peter@pgacon.com .
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date