Delete Regedit Key Windows

Asked

Viewed 415 times

2

I’m making a program in C# to automate a situation here in the company, only that I am facing problems with it

I am wanting to delete a windows registry key gets located on HKEY_LOCAL_MACHINE SOFTWARE Microsoft Mslicensing

In case I’d like to delete the key Mslicensing or delete everything within it.

I’m using the following command

string caminho = @"SOFTWARE\Microsoft\MSLicensing";
Registry.LocalMachine.DeleteSubKey(caminho, true);

I am running VS as an administrator I already put a manifest with high level and still can not delete.

Thank you for your attention.

  • I think instead of Registry would be the RegistryKey of Microsoft.Win32... But why are you wanting to do this? Mslicensing is just one example and you intend to delete the registration of a software your own?

  • Check out the Microsoft documentation (https://docs.microsoft.com/en-us/windows/win32/winprog64/shared-registry-keys). Could be key redirection problem, I’ve had problems of this type.

1 answer

1

First, add this reference:

using Microsoft.Win32;

And to delete use this snippet:

string keyName = @"SOFTWARE\Microsoft\MSLicensing";
RegistryKey key = Registry.CurrentUser.OpenSubKey(keyName, true);
key.DeleteValue("ValorASerDeletado");
  • Hello. I used the command you passed and it is returning me the following error Object reference not set for an instance of an object. , my code is as follows. 

string keyName = @"SOFTWARE\Microsoft\MSLicensing\Store\LICENSE000";
RegistryKey key = Registry.LocalMachine.OpenSubKey(keyName, true);
key.DeleteValue("ClientLicense");

  • Key is being null for some reason. Perform a validation if Key is null and evaluate whether the record you are trying to delete exists and is valid.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.