Geoff Chappell - Software Analyst
This function makes a given directory into a system folder.
BOOL PathMakeSystemFolder (LPTSTR pszPath);
The function exists in ANSI and Unicode forms.
The pszPath argument provides the address of a null-terminated string that names the directory that is to be made a system folder.
The function returns TRUE for success, else FALSE for failure.
The function fails trivially if pszPath is NULL or the string at pszPath is empty. Given a path, the function’s work falls into two parts. The first acts on the directory and is required for the function’s success. The second is concerned with a “desktop.ini” file in the directory, should one exist, and is merely desirable.
The first part succeeds trivially if the named path is that of the Windows directory or the System directory (in the sense of the standard API functions GetWindowsDirectory and GetSystemDirectory). For other directories, some work is always attempted on the directory’s file attributes, and the function fails if the file system object represented by the given path does not have the directory attribute.
A system folder must have either the read-only or system attribute set. This function sets one and clears the other. The choice depends on the UseSystemForSystemFolders value under the Software\Microsoft\Windows\CurrentVersion\Explorer key in the HKEY_LOCAL_MACHINE branch of the registry. The attribute that the function sets is the system attribute, if this value is present, else the read-only attribute. The function fails if it cannot set and clear these attributes for the given directory.
The act of making a directory into a system folder is considered a modification. The function updates the directory’s last-write time and sends a corresponding change notification. This change is merely desirable: failure does not affect the function’s success.
Except if pszPath is trivial, i.e., even on failure of the first part, the function sets the hidden and system attributes for a “desktop.ini” file on the given path. Again, this change is merely desirable: failure does not affect the function’s success.
The PathMakeSystemFolder function is exported by name (with ANSI and Unicode suffixes) from SHLWAPI in version 4.71 and higher.
Though it is only an implementation detail, it is as well to note that the UseSystemForSystemFolders value in the registry seems to be undocumented except for its presentation as magic in one Microsoft Knowledge Base article Unable to Remove Read-Only Attribute from Folder.