Accessing Registry using ASP.NET


In this article, we will see how to access the registry using ASP.NET. We will see one simple example to check where Visual Studio installed on our machine.

Microsoft provides namespace named Microsoft.Win32 which handles events raised by the operation system and manipulate the system registry. Some of the members that related to registry are

   1. Registry Class - This class contains base RegisterKey that access values and subkeys in the registry.

   2. RegistryKey Class - This class represents a key level node in the windows registry.

   3. RegistryHive Enumeration - This represents possible top-level nodes on a foreign machine.

Sample :

Import Microsoft.Win32 in your code-behind file

using Microsoft.Win32;

On Page_Load ,add the below lines

RegistryKey objRk = Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("Microsoft") .OpenSubKey("VisualStudio").OpenSubKey("7.1");
Response.Write(objRk.GetValue("InstallDir").ToString());

This will return the path where your visual studio is installed.

Hope you will find this article interesting and useful .


Similar Articles