0

I am trying to access Software\Microsoft\Windows\CurrentVersion\Group Policy Objects{AEE4EB78-4042-42EC-9C84-D08BA6C3047B}Machine\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate to read update value PauseFeatureUpdatesStartTime.

Trying to access entire path was failing, so I started trying it iece by piece.

key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion"); worked fine but

key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Group Policy Objects"); fails with key equal to NULL?!?

I believe the key path is correct because I am displaying it in regedit and regedit is displaying "Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Group Policy Objects{AEE4EB78-4042-42EC-9C84-D08BA6C3047B}Machine\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" as the path.

NOTE!!! these keys\values may not exist if you have not "activated" then with gpedit.msc. In gpedit, look for "Computer Configuration\Administrative Templates\Windows Components\Windows Update\Windows Update For Business". You have to "activate" the first two items.

Any thoughts?

thanks,

spinlock
  • 17
  • 3
  • (1) What exactly do you mean by "*...fails?!?"*? Do you get an error? If yes, which one? Please [edit] your question to include that information. (2) Are you sure the registry key is correct? I don't have `HKCU\Software\Microsoft\Windows\CurrentVersion\Group Policy Objects` on my machine... – Heinzi Nov 20 '21 at 21:02
  • it fails by setting key = NULL – spinlock Nov 20 '21 at 21:09
  • 1
    this may help https://stackoverflow.com/a/13729137/2011071 – Serg Nov 20 '21 at 21:16
  • @Serg: That only applies to HKLM, no? – Heinzi Nov 20 '21 at 21:25
  • So, does the key exist in your system? Did you check with regedit? – Heinzi Nov 20 '21 at 21:26
  • @Heinzi, As I know, Windows use the same approach for all hives, not only for HKLM. – Serg Nov 20 '21 at 21:30
  • Thanks for that link Serg. I changed to code by adding var hkcu = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64); var key = hkcu.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Group Policy Objects"); BUT key is still NULL after OpenSubKey(). – spinlock Nov 20 '21 at 22:28
  • You wrote regedit displays `Group Policy Objects{AEE4EB78-4042-42EC-9C84-D08BA6C3047B}Machine` as a single keyname, so is this a typo missing two \ characters or a really weird single keyname? – Steeeve Nov 21 '21 at 09:41
  • not a type, I copy pasted exactly what regedit was displaying. I don't understand the syntax with curly brackets, but this is what it displays. BTW, I started cutting the pathname down to debug, and all of that is out of my code now and still returning NULL. My current code is only using @"Software\Microsoft\Windows\CurrentVersion\Group Policy Objects" and this is failing. – spinlock Nov 21 '21 at 23:22
  • 1
    @Serg: Nope, only the `Software\Classes` subkey of HKCU gets WOW redirection, the remainder of HKCU is shared between 32- and 64-bit applications. See https://learn.microsoft.com/en-us/windows/win32/winprog64/shared-registry-keys – Heinzi Nov 22 '21 at 09:52
  • @spinlock Then, there is no key named `Software\Microsoft\Windows\CurrentVersion\Group Policy Objects`, so you can't open it. You can only open the existing key as shown by regedit. `{AEE4EB78-4042-42EC-9C84-D08BA6C3047B}Machine` is not a subkey. – Steeeve Nov 22 '21 at 18:03
  • Steeeve, regedit shows HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Group Policy Objects and when I right click on it, one action is Copy Key Name. NOTE!!! these keys\values may not exist on a system that has not "Enabled" "Computer Configuration\Administrative Templates\Windows Components\Windows Update\Windows Update For Business" with gpedit.msc. In gpedit look for this group and Enable the first two items. Then your system will have these keys/values – spinlock Nov 23 '21 at 19:44
  • I did more debug: in Software\Microsoft\Windows\CurrentVersion\ I opened "Lock Screen" successfully. This proves that spaces in the subKeyName are not the issue. – spinlock Nov 28 '21 at 21:55
  • SOLVED!! it was an authority issue!! I develop under a standard user, I finally opened a cmd window as Administrator and it works fine! OpenSubKey() takes the entire path and returns a valid key handle!! this raises another issue becuase when run under Administrator, it open the Administrator "CurrentUser". I want to change all users on the system so Windows will stop ramming updates down my throat. – spinlock Nov 30 '21 at 02:44

0 Answers0