How do I prevent folders like My Pictures from being recreated?

Raymond Chen

Another converse of How do I programmatically create folders like My Pictures if they were manually deleted? and Why do folders like “My Pictures” come back after I delete them? is How do I prevent folders like My Pictures from being recreated? Starting in Windows 7, there is a group policy called Disable Known Folders which lets you specify a list of known folders which should be disabled. If somebody tries to create a known folder programmatically, the call will fail with ERROR_ACCESS_DISABLED_BY_POLICY.

Note that this policy only blocks creation of the folder. If the folder already exists, then the policy has no effect. (You’re locking the door after the horse has bolted.)

0 comments

Discussion is closed.

Feedback usabilla icon