Re: Deleting registry hive root key

2022-04-28 Thread Greg Keogh
>
> Reading the source code, ClassesRoot is opened as writable – have you
> tried just calling DeleteSubKeyTree on it?
>

I have figured out what went wrong last week.

I originally had a string of permission failures because I forgot to
call OpenSubKey
with writable: true. Once I fixed those stupid mistakes I hit another error
on the HKCR root delete and I didn't read the message properly and assumed
it was a permission failure. Today I see the message is:

System.InvalidOperationException: Registry key has subkeys and recursive
removes are not supported by this method.

I had accidentally used DeleteSubKey instead of DeleteSubKey*Tree* and
didn't read the error message. I blame intellisense first and me second.

*Greg*

P.S. I haven't done any COM work for 10 years and I forgot how messy it is.
I confirmed today my old suspicion that a regasm for a simple C# class
creates dozens of registry entries in different branches, and although an
inverse /unregister does remove a lot of keys, it does not remove the
typelib and interface keys. So a regasm slowly pollutes the registry,
slightly, if that matters.


Re: Deleting registry hive root key

2022-04-28 Thread Greg Keogh
>
> Reading the source code, ClassesRoot is opened as writable – have you
> tried just calling DeleteSubKeyTree on it?
>

I forgot about the source code! I think that was the first thing I did, but
I'll run a fresh experiment with a fresh mind later today and see what
happens -- *Greg*


Re: Deleting registry hive root key

2022-04-21 Thread Preet Sangha
Ahh sorry - I read your original message as implying it was locked and
couldn't be deleted normally as it was loaded - my bad.

Another couple of thoughts:

1. HKCR seems to be actually linked to another key in HK LM or HK
CU perhaps deleting it there instead?
2. perhaps interop dll to do it? for instance

- RegOpenKeyEx
- RegDeleteKey
- RegEnumKeyEx

(
https://docs.microsoft.com/en-us/windows/win32/sysinfo/deleting-a-key-with-subkeys
)

regards,
Preet, in Auckland NZ



On Fri, 22 Apr 2022 at 13:55, Greg Keogh  wrote:

> OZ calling NZ. From the command prompt I can delete the key:
>
> > reg delete HKCR\MyKeyToDelete
>
> I need the C# code equivalent of this. I'll bet there's a trick for this
> hidden somewhere in plain sight?! It doesn't seem dangerous or obscure
> enough for special procedures like mounting hives.
>
> *Greg*
>
> On Fri, 22 Apr 2022 at 11:29, Preet Sangha  wrote:
>
>> I kind of get the feeling that this is something that would be done by
>> mounting the hive in another instance of windows or perhaps a live Linux,
>> or during the set. I cant see how you'd do it programmatically I'm afraid
>> (unless your program is a low level on running in the pre-boot stage - like
>> when you set up a new os).
>>
>> I did find this - but it's old and may not be very useful:
>> https://www.raymond.cc/blog/how-to-edit-windows-registry-key-values-without-booting-in-windows/
>>
>>
>> regards,
>> Preet, in Auckland NZ
>>
>>>


Re: Deleting registry hive root key

2022-04-21 Thread Greg Keogh
OZ calling NZ. From the command prompt I can delete the key:

> reg delete HKCR\MyKeyToDelete

I need the C# code equivalent of this. I'll bet there's a trick for this
hidden somewhere in plain sight?! It doesn't seem dangerous or obscure
enough for special procedures like mounting hives.

*Greg*

On Fri, 22 Apr 2022 at 11:29, Preet Sangha  wrote:

> I kind of get the feeling that this is something that would be done by
> mounting the hive in another instance of windows or perhaps a live Linux,
> or during the set. I cant see how you'd do it programmatically I'm afraid
> (unless your program is a low level on running in the pre-boot stage - like
> when you set up a new os).
>
> I did find this - but it's old and may not be very useful:
> https://www.raymond.cc/blog/how-to-edit-windows-registry-key-values-without-booting-in-windows/
>
>
> regards,
> Preet, in Auckland NZ
>
>>


Re: Deleting registry hive root key

2022-04-21 Thread Preet Sangha
I kind of get the feeling that this is something that would be done by
mounting the hive in another instance of windows or perhaps a live Linux,
or during the set. I cant see how you'd do it programmatically I'm afraid
(unless your program is a low level on running in the pre-boot stage - like
when you set up a new os).

I did find this - but it's old and may not be very useful:
https://www.raymond.cc/blog/how-to-edit-windows-registry-key-values-without-booting-in-windows/


regards,
Preet, in Auckland NZ



On Fri, 22 Apr 2022 at 13:15, Greg Keogh  wrote:

> Folks, TGIF
>
> I have to delete a registry key that is a direct child of the
> HKEY_CLASSES_ROOT hive.
>
> Normally deleting a key is easy because you just open the parent key as
> writable and call DeleteSubKeyTree.
>
> In this case the parent is the HKCR hive itself, and I can't figure out
> how to open it as writable. The Registry.ClassesRoot property is static and
> has no open methods.
>
> Chers,
> *Greg K*
>


Deleting registry hive root key

2022-04-21 Thread Greg Keogh
Folks, TGIF

I have to delete a registry key that is a direct child of the
HKEY_CLASSES_ROOT hive.

Normally deleting a key is easy because you just open the parent key as
writable and call DeleteSubKeyTree.

In this case the parent is the HKCR hive itself, and I can't figure out how
to open it as writable. The Registry.ClassesRoot property is static and has
no open methods.

Chers,
*Greg K*