Why can’t I use SHSetKnownFolderPath to change the location of FOLDERID_LocalAppData?

Raymond Chen

A customer observed that their unit test started failing in Windows 10 version 1803. Specifically, it failed here:

SHSetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, temporaryDirectory);

with the error E_INVALID­ARG. What happened in Windows 10 version 1803 to make this call invalid?

The change to block relocation of the Local­App­Data folder, as well as its close personal friend Local­App­Data­Low, was an acknowledgement of reality: Earlier versions of Windows allowed you to relocate those directories, but the result was a corrupted user profile, forcing you to delete the user and start over.

The reason is that there are some system files in those directories which are perpetually locked and consequently cannot be moved to their new home. The next time the user logs on, the system tries to reopen the files and can’t, and things rapidly go downhill from there.

Relocation of these directories is blocked to prevent you from shooting yourself in the foot. It’s an acknowledgement of the reality that it not only doesn’t work, but leaves the user profile corrupted.