Need to allow app to "delete" HKCU registry keys/items.

%3CLINGO-SUB%20id%3D%22lingo-sub-1479528%22%20slang%3D%22en-US%22%3ENeed%20to%20allow%20app%20to%20%22delete%22%20HKCU%20registry%20keys%2Fitems.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1479528%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20a%20specific%20application%20in%20mind%2C%20but%20this%20is%20a%20general%20issue%20with%20the%20containerized%20registry.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20application%20is%20Fiddler%2C%20and%20it%20throws%20an%20exception%20when%20shutting%20down.%26nbsp%3B%20The%20app%20has%20a%20HKCU%20based%20key%20for%20preferences%20which%20it%20reads%20at%20startup%2C%20but%20then%20deletes%20when%20shutting%20down.%26nbsp%3B%20Why%3F%20I'm%20not%20sure%20but%20let's%20assume%20it%20is%20trying%20to%20be%20a%20good%20program%20and%20clean%20up%20after%20itself.%26nbsp%3B%20Such%20an%20operation%20was%20always%20allowed%20under%20the%20Win32%20runtime%2C%20but%20an%20access%20denied%20occurs%20and%20the%20app%20throws%20an%20exception.%20I%20am%20attaching%20images%20of%20the%20application%20error%20popup%2C%20ProcMon%20trace%20showing%20the%20ACCESS_DENIED%2C%20as%20well%20as%20the%20call%20stack%20showing%20it%20was%20calling%20NtDeleteKeyEx.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20don't%20want%20the%20app%20to%20delete%20any%20registry%20item%20in%20the%20immutable%20system%20copy%20of%20the%20hive%2C%20just%20like%20we%20don't%20want%20it%20to%20write%20to%20it%20or%20add%20to%20it.%26nbsp%3B%20But%20as%20we%20have%20seen%20with%20registry%20write%20calls%2C%20it%20is%20necessary%20to%20allow%20apps%20to%20make%20such%20attempts%20and%20we%20work%20around%20it.%26nbsp%3B%20Recent%20changes%20to%20the%20MSIX%20Runtime%20allow%20writing%20to%20certain%20parts%20of%20the%20containerized%20registry%2C%20presumably%20using%20some%20sort%20of%20redirection%20to%20the%20user's%20application%20container%2C%20keeping%20the%20system%20copy%20intact%20but%20allowing%20the%20user%20to%20have%20an%20altered%20state.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20similarly%20need%20to%20allow%20apps%20to%20delete%20keys%20and%20items.%20This%20was%20similarly%20accomplished%20in%20App-V%20by%20the%20use%20of%20high-order%20bits%20in%20registry%20type%20fields%20(on%20the%20item%20itself%2C%20or%20in%20the%20case%20of%20a%20registry%20key%20by%20setting%20the%20high-order%20bit%20on%20the%20%22default%20item%22%20of%20the%20key)%20in%20the%20redirected%20area.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20see%20three%20possible%20approaches%20to%20solving%20this%20issue%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3E%26nbsp%3BA%20full%20support%20for%20all%20registry%20operations%20in%20the%20MSIX%20Runtime%2C%20using%20redirection%20spoofing.%20One%20comprehensive%20change%20supporting%20full%20spoofed%20access%20to%20HKLM%20and%20HKCU%20in%20the%20redirected%20app%20container.%26nbsp%3B%20This%20is%20a%20complete%20and%20clean%20solution%20to%20any%20containerized%20registry%20issues.%3C%2FLI%3E%0A%3CLI%3E%26nbsp%3BAdding%20support%20in%20the%20PSF%20to%20spoof%20specific%20operations%20on%20specific%20items%2C%20by%20implementing%20a%20redirection%20to%20a%20per-package%20location%20in%20the%20non-containerized%20user%20hive.%20This%20piecemeal%20approach%20has%20the%20advantage%20of%20being%20more%20targeted%2C%20but%20far%20more%20complicated%20for%20everyone%20involved.%20And%20it%20wouldn't%20be%20cleaned%20up%20with%20the%20package%20is%20uninstalled%20(unless%20we%20get%20an%20uninstall%20script%20capability).%3C%2FLI%3E%0A%3CLI%3EAdding%20support%20in%20the%20Psf%20RegLegacyFixups%20for%20a%20new%20fixup%20type%20that%20simply%20spoofs%20the%20delete%20by%20telling%20the%20app%20that%20it%20did%20it%2C%20even%20when%20it%20didn't.%26nbsp%3B%20Advantage%20of%20more%20targeted%20and%20isn't%20leaving%20anything%20behind%2C%20but%20probably%20is%20more%20limited%20in%20what%20it%20can%20fix.%26nbsp%3B%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20can%20move%20ahead%20and%20build%20either%20%232%20or%20%233%2C%20but%20really%20want%20Microsoft%20to%20weigh%20in%20on%20this%20as%20there%20is%20no%20sense%20in%20duplication%20of%20work.%26nbsp%3B%20My%20preference%20is%20idea%20%231%2C%20but%20it%20isn't%20the%20first%20time%20I%20have%20asked%20for%20this.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1498603%22%20slang%3D%22en-US%22%3ERe%3A%20Need%20to%20allow%20app%20to%20%22delete%22%20HKCU%20registry%20keys%2Fitems.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1498603%22%20slang%3D%22en-US%22%3E%3CP%3EIs%20anybody%20investigating%2Fevaluating%20this%3F%20We've%20also%20seen%20apps%20that%20require%20elevation%20after%20being%20packaged%20as%20an%20MSIX%20just%20because%20the%20app%20is%20trying%20to%20write%20under%20HKCU.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1509920%22%20slang%3D%22en-US%22%3ERE%3A%20Need%20to%20allow%20app%20to%20%22delete%22%20HKCU%20registry%20keys%2Fitems.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1509920%22%20slang%3D%22en-US%22%3ESupport%20for%20this%20fixup%20is%20part%20of%20PR%20%23150%20now%20submitted%20to%20the%20Microsoft%20Develop%20branch.%20It%20is%20a%20new%20type%20added%20to%20RegLegacyFixups.%20In%20essence%2C%20it%20allows%20one%20to%20specify%20keys%2Fregistry%20items%20for%20which%20if%20the%20app%20tries%20to%20delete%20it%20to%20ignore%20the%20error%20and%20return%20success.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1518901%22%20slang%3D%22en-US%22%3ERE%3A%20Need%20to%20allow%20app%20to%20%22delete%22%20HKCU%20registry%20keys%2Fitems.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1518901%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F146612%22%20target%3D%22_blank%22%3E%40TIMOTHY%20MANGAN%3C%2FA%3E%26nbsp%3B%20The%20PR%20is%20now%20completed%20and%20is%20part%20of%20the%20Microsoft%20Develop%20branch.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EA%20build%20of%20this%20PSF%20is%20also%20included%20in%20the%20new%20PsfTooling%20version%204.0.%2C%20available%20in%20the%20Microsoft%20Store%20(free).%3C%2FP%3E%3C%2FLINGO-BODY%3E
MVP

I have a specific application in mind, but this is a general issue with the containerized registry. 

 

The application is Fiddler, and it throws an exception when shutting down.  The app has a HKCU based key for preferences which it reads at startup, but then deletes when shutting down.  Why? I'm not sure but let's assume it is trying to be a good program and clean up after itself.  Such an operation was always allowed under the Win32 runtime, but an access denied occurs and the app throws an exception. I am attaching images of the application error popup, ProcMon trace showing the ACCESS_DENIED, as well as the call stack showing it was calling NtDeleteKeyEx.

 

We don't want the app to delete any registry item in the immutable system copy of the hive, just like we don't want it to write to it or add to it.  But as we have seen with registry write calls, it is necessary to allow apps to make such attempts and we work around it.  Recent changes to the MSIX Runtime allow writing to certain parts of the containerized registry, presumably using some sort of redirection to the user's application container, keeping the system copy intact but allowing the user to have an altered state.

 

We similarly need to allow apps to delete keys and items. This was similarly accomplished in App-V by the use of high-order bits in registry type fields (on the item itself, or in the case of a registry key by setting the high-order bit on the "default item" of the key) in the redirected area.

 

I see three possible approaches to solving this issue:

  1.  A full support for all registry operations in the MSIX Runtime, using redirection spoofing. One comprehensive change supporting full spoofed access to HKLM and HKCU in the redirected app container.  This is a complete and clean solution to any containerized registry issues.
  2.  Adding support in the PSF to spoof specific operations on specific items, by implementing a redirection to a per-package location in the non-containerized user hive. This piecemeal approach has the advantage of being more targeted, but far more complicated for everyone involved. And it wouldn't be cleaned up with the package is uninstalled (unless we get an uninstall script capability).
  3. Adding support in the Psf RegLegacyFixups for a new fixup type that simply spoofs the delete by telling the app that it did it, even when it didn't.  Advantage of more targeted and isn't leaving anything behind, but probably is more limited in what it can fix. 

 

I can move ahead and build either #2 or #3, but really want Microsoft to weigh in on this as there is no sense in duplication of work.  My preference is idea #1, but it isn't the first time I have asked for this.

3 Replies

Is anybody investigating/evaluating this? We've also seen apps that require elevation after being packaged as an MSIX just because the app is trying to write under HKCU.

Support for this fixup is part of PR #150 now submitted to the Microsoft Develop branch. It is a new type added to RegLegacyFixups. In essence, it allows one to specify keys/registry items for which if the app tries to delete it to ignore the error and return success.

@TIMOTHY MANGAN  The PR is now completed and is part of the Microsoft Develop branch.

 

A build of this PSF is also included in the new PsfTooling version 4.0., available in the Microsoft Store (free).