Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The GetValue method of the My.Computer.Registry object can be used to determine whether a given value exists in a specific registry key.
When reading the registry from a Web application, the current user depends on the authentication and impersonation implemented in the Web application.
To determine whether a value exists in a registry key
Use the GetValue method to retrieve the value. The following code checks the value and returns a message if it does not exist.
If My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\TestApp", "TestValue", Nothing) Is Nothing Then MsgBox("Value does not exist.") End If
Robust Programming
The following conditions may cause an exception:
The name of the key is Nothing (ArgumentNullException).
The user does not have permissions to create registry keys (SecurityException).
The key name exceeds the 255-character limit (ArgumentException).
The key is closed (IOException).
The registry key is read-only (UnauthorizedAccessException).
Security
To run this process, your assembly requires a privilege level granted by the RegistryPermission class. If you are running in a partial-trust context, the process might throw an exception due to insufficient privileges. Similarly, the user must have the correct access control lists for creating or writing to settings. For example, a local application that has the code access security permission might not have operating system permission. For more information, see Code Access Security Basics.
See Also
Tasks
Troubleshooting: Manipulating the Registry (Visual Basic)