{"id":13213,"date":"2010-08-06T07:00:00","date_gmt":"2010-08-06T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2010\/08\/06\/some-known-folders-cannot-be-moved-but-others-can-and-youll-just-have-to-accept-that\/"},"modified":"2010-08-06T07:00:00","modified_gmt":"2010-08-06T07:00:00","slug":"some-known-folders-cannot-be-moved-but-others-can-and-youll-just-have-to-accept-that","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20100806-00\/?p=13213","title":{"rendered":"Some known folders cannot be moved, but others can, and you&#039;ll just have to accept that"},"content":{"rendered":"<p>Locations in the shell known folder system  can be marked as <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb762512.aspx\"> <code>KF_CATEGORY_FIXED<\/code><\/a>, which makes them immovable. Conversely, if a file system folder is not immovable, then it can be moved.\n This dichotomy appears simple and unworthy of discussion, except that customers sometimes have trouble incorporating this concept into their world view.<\/p>\n<blockquote class=\"q\"><p> I have some code that calls <code>SHSet&shy;Folder&shy;Path<\/code>, and it works for most of the folders I&#8217;m interested in, but for some <code>CSIDL<\/code> values like <code>CSIDL_COMMON_APPDATA<\/code>, it fails with <code>E_INVALIDARG<\/code>. Doesn&#8217;t matter if I run elevated or not. What am I doing wrong? <\/p><\/blockquote>\n<p> The difference is that <code>CSIDL_COMMON_APPDATA<\/code> (known under the New World Order as <code>FOLDERID_ProgramData<\/code>) is marked as <code>KF_CATEGORY_FIXED<\/code> so it cannot be moved.<\/p>\n<blockquote class=\"q\"><p> Is there a way that we can override the <code>KF_CATEGORY_FIXED<\/code> flag and move it anyway? <\/p><\/blockquote>\n<p> Nope. It&#8217;s immovable. Sorry. You&#8217;ll just have to accept that that folder will not go where you want it.\n The very next day, we got a complementary question from an unrelated customer:<\/p>\n<blockquote class=\"q\"><p> We have a program that monitors a known folder, and it goes haywire if the user changes the location of the folder while it&#8217;s being monitored. Is there a way to prevent the user from moving the folder? <\/p><\/blockquote>\n<p> If a known folder can be moved, then you have to accept that it can be moved. You can&#8217;t override its category and force it to be <code>KF_CATEGORY_FIXED<\/code> just because your life would be easier if it were.\n I found it interesting that we got two requests on consecutive days asking for what appear to be opposite things: &#8220;I want to force this folder to be movable&#8221; and &#8220;I want to force this folder to be immovable.&#8221; I can only imagine what would happen if both programs are running at the same time!<\/p>\n<p> What the program can do is register an <code>IFile&shy;Is&shy;In&shy;Use<\/code> on the directory so that it will be called when somebody wants to move it. At least that way it knows when scary things are about to happen and can prepare itself for the changes that lie ahead. I&#8217;m told that <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ee330722(VS.85).aspx\"> a sample program illustrating <code>IFile&shy;Is&shy;In&shy;Use<\/code><\/a> is in the Windows&nbsp;7 SDK under the directory <code>winui\\Shell\\AppPlatform\\FileIsInUse<\/code>. There&#8217;s also <a href=\"http:\/\/web.archive.org\/web\/20070429124756\/http:\/\/shellrevealed.com\/blogs\/shellblog\/archive\/2007\/03\/29\/Your-File-Is-In-Use_2620_-Demystified.aspx\"> an old article on the subject<\/a> over on the now-defunct Shell Revealed blog. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Locations in the shell known folder system can be marked as KF_CATEGORY_FIXED, which makes them immovable. Conversely, if a file system folder is not immovable, then it can be moved. This dichotomy appears simple and unworthy of discussion, except that customers sometimes have trouble incorporating this concept into their world view. I have some code [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-13213","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Locations in the shell known folder system can be marked as KF_CATEGORY_FIXED, which makes them immovable. Conversely, if a file system folder is not immovable, then it can be moved. This dichotomy appears simple and unworthy of discussion, except that customers sometimes have trouble incorporating this concept into their world view. I have some code [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/13213","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=13213"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/13213\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=13213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=13213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=13213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}