You must wrap your code in a using block, which indirectly calls Dispose for you. It is not clear which static analysis tool you are using, but hopefully it understands using :
using (RegistryKey installKey = Registry.LocalMachine.OpenSubKey(installKey)) {
Note that you can also explicitly call Dispose , but you must first drop RegistryKey to IDisposable :
((IDisposable)installKey).Dispose()
source share