Click here to Skip to main content
Licence 
First Posted 2 Apr 2007
Views 14,484
Downloads 370
Bookmarked 12 times

Registry Clean Automation for Windows Service

By | 2 Apr 2007 | Article
This application demonstrates to create custom subkeys in registry while installing/uninstalling windows service.
Screenshot - ServiceRegistryClean1.jpg

Introduction

Microsoft.Win32.Registry.LocalMachine

This class provides the set of standard root keys found in the registry on machines running Windows. The registry is a storage facility for Information about applications, users, and default system settings. For example, applications can use the registry for storing information that needs to be preserved after the application is closed, and access that same information when the application is reloaded. For instance, you can store color preferences, screen locations, or the size of the window. You can control this data for each user by storing the information in a different location in the registry.

The base, or root RegistryKey instances that are exposed by the Registry class delineate the basic storage mechanism for subkeys and values in the registry. All keys are read-only because the registry depends on their existence. Please go through the following steps.

Step 1:

In ProjectInstaller.vb add the following methods as override.

For Install

Public Overrides Sub Install(ByVal stateServer As IDictionary) 
    MyBase.Install(stateServer)
    Dim rkSystem, rkCurrentControlSet, rkServices, rkService, rkSubKey As RegistryKey
    rkSystem = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("System") 
    rkCurrentControlSet= rkSystem.OpenSubKey("CurrentControlSet") 
    rkServices = rkCurrentControlSet.OpenSubKey("Services")
    rkService = rkServices.OpenSubKey(Me.ServiceInstaller1.ServiceName, True) 
    rkService.SetValue("Description","Test Service") 
    rkSubKey = rkService.CreateSubKey("CHILD") 
End Sub 

For Uninstall

Public Overrides Sub Uninstall(ByVal stateServer As IDictionary) 
    Dim rkSystem,rkCurrentControlSet, rkServices, rkService As RegistryKey 
    rkSystem = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("System")
    rkCurrentControlSet = rkSystem.OpenSubKey("CurrentControlSet") 
    rkServices = rkCurrentControlSet.OpenSubKey("Services")
    rkService = rkServices.OpenSubKey(Me.ServiceInstaller1.ServiceName, True) 
    rkService.DeleteSubKeyTree("CHILD")
    MyBase.Uninstall(stateServer)
End Sub 

Step 2:

Build the windows service project and deploy the project. In deployment project, add primary output to install and uninstall custom actions. Refer. Image2 & Image3

Image2

Screenshot - ServiceRegistryClean2.jpg

Image3

Screenshot - ServiceRegistryClean3.jpg

Final notes

I hope that you found this article useful. If you found this article stupid, annoying, incorrect, etc. express this fact by rating the article as you see fit. However I would appreciate if you would leave a comment explaining your reasons so that I can (hopefully) learn from my mistakes.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Jay7093

Web Developer

India India

Member

My main goal as a developer is to improve the way software is designed, and how it interacts with the user.
I have extensive knowledge of the .NET Framework, SQL Server, Javascript. I specialize in working with VS 2005,AJAX,XSLT, Windows Services, COM+ and SQL 2005.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120517.1 | Last Updated 2 Apr 2007
Article Copyright 2007 by Jay7093
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid