Click here to Skip to main content
13,250,043 members (65,461 online)
Click here to Skip to main content
Add your own
alternative version


12 bookmarked
Posted 2 Apr 2007

Registry Clean Automation for Windows Service

, 2 Apr 2007
Rate this:
Please Sign up or sign in to vote.
This application demonstrates to create custom subkeys in registry while installing/uninstalling windows service.
Screenshot - ServiceRegistryClean1.jpg



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) 
    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) 
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


Screenshot - ServiceRegistryClean2.jpg


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.


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

Web Developer iInterchange Systems
India India
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.

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171114.1 | Last Updated 2 Apr 2007
Article Copyright 2007 by Jay7093
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid