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
 

Write Your Own Windows Services : Page 6

If you're using Windows, you're no stranger to Windows services, but do you know how to write one of your own? In this article, you'll learn not only how to build your own Windows service, but how to build a client with which to control it.


advertisement
Testing the Application
Before you test the application, verify that you have successfully installed the Windows service you created earlier. Then press F5 in Visual Studio 2005. Try starting, pausing, and stopping the service to verify that the Windows service works.

With the Windows service running, you can perform the following steps to verify that the Windows service works as intended:

  • Create a new Word document in C:\.
  • Name it as Exam Questions.doc.


  • Rename it as Test Questions.doc.
Now go to C:\ and open up the WordDocumentsHistory.txt file. You should see something like this:

2/25/2007 10:30:49 PM: WordFilesMonitor Started 2/25/2007 10:30:57 PM: File Created : C:\New Microsoft Word Document.doc 2/25/2007 10:30:57 PM: File Changed : C:\WINDOWS\SHELLNEW\WINWORD8.DOC 2/25/2007 10:30:57 PM: File Changed : C:\New Microsoft Word Document.doc 2/25/2007 10:31:07 PM: File : C:\New Microsoft Word Document.doc renamed to C:\Exam Questions.doc 2/25/2007 10:31:07 PM: File Changed : C:\Exam Questions.doc 2/25/2007 10:31:24 PM: File : C:\Exam Questions.doc renamed to C:\Test Questions.doc 2/25/2007 10:31:24 PM: File Changed : C:\Test Questions.doc 2/25/2007 10:33:48 PM: File Deleted : C:\Test Questions.doc 2/25/2007 10:33:48 PM: File Created : C:\RECYCLER\S-1-5-21-790525478-1425521274-839522115-1003\Dc2398.doc 2/25/2007 10:33:48 PM: File Changed : C:\RECYCLER\S-1-5-21-790525478-1425521274-839522115-1003\Dc2398.doc

Figure 9. The Task Bar: Showing the running application.

This WordDocumentsHistory.txt log file keeps track of all the files activities (with .doc extension).

Also observe that when the application is running, it has an entry in the task bar, as shown in Figure 9). When it is minimized, the entry in the task bar remains.

But when you click the "x" button, the entry in the task bar is gone. To bring the application back up, you can either double-click on the notify icon in the System Tray, or right-click on it and select the Options… menu item.

Summary
With some creativity, you can now write some cool, new utilities using Visual Studio 2005. If you have some cool ideas on how to use Windows services, email me. I would like to hear them.



Wei-Meng Lee is a Microsoft MVP and founder of Developer Learning Solutions, a technology company specializing in hands-on training on the latest Microsoft technologies. He is an established developer and trainer specializing in .NET and wireless technologies. Wei-Meng speaks regularly at international conferences and has authored and coauthored numerous books on .NET, XML, and wireless technologies. He writes extensively on topics ranging from .NET to Mac OS X. He is also the author of the .NET Compact Framework Pocket Guide, ASP.NET 2.0: A Developer's Notebook (both from O'Reilly Media, Inc.), and Programming Sudoku (Apress). Here is Wei-Meng's blog.
Comment and Contribute

 

 

 

 

 


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

 

 

Sitemap