Delete Registry Key on a remote computer

I just want to delete a registry Key on a remote Computer5, the registry key is

HKEY_LOCAL_MACHINE\SOFTWARE\Testing

I have the code in place but keep getting "cannot write to Registry" althought i have full admin and registry rights on this PC.

Here is the code
string Computer5 = TextBox2.Text; 

Open in new window



RegistryKey key = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, Computer5).OpenSubKey("Software");
                key.DeleteSubKey("Testing");
                key.Close();

Open in new window


this is domain enviroment
kentrg11Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kentrg11Author Commented:
any help/leads appreticated
0
piattndCommented:
RegistryKey myKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, "computername");
            myKey.DeleteSubKey(@"SOFTWARE\test");

Open in new window

0
piattndCommented:
When you open the subkey, you need to establish it as writeable:

RegistryKey myKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, "test");
            RegistryKey mySubKey = myKey.OpenSubKey("SOFTWARE",true);
            mySubKey.DeleteSubKey("test");

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

piattndCommented:
In my example, I'm using 2 RegistryKey variables, but you don't need to.  Just add the ",true" to your opensubkey section and you should be fine.
0
kentrg11Author Commented:
I have this code below as you've advised but im getting the follow error message
"Cannot delete a subkey tree because the subkey does not exist."
i confirmed there is a key on computerName called SOFTWARE/Testing

RegistryKey myKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, computerName);
                RegistryKey mySubKey = myKey.OpenSubKey("SOFTWARE", true);
                mySubKey.DeleteSubKey("Testing");

Open in new window

0
piattndCommented:
Can you confirm that the Testing key in Software is in the HKLM not the HKCU location?
0
kentrg11Author Commented:
just copy and pasted  this from the remote Computer im trying to access
HKEY_LOCAL_MACHINE\SOFTWARE\Testing

the code again is

RegistryKey myKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, computerName);
                RegistryKey mySubKey = myKey.OpenSubKey("SOFTWARE", true);
                mySubKey.DeleteSubKey("Testing", true);
                myKey.Close();

Open in new window

0
kentrg11Author Commented:
figured it out , had to add RegistryView.Registry64);
0
kentrg11Author Commented:
excellent
0
piattndCommented:
Sorry I was so late in getting back to this.  Glad you found the missing piece!  Good luck!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.