10

I want to create a folder and pin it to the Navigation Pane in Windows Explorer, but I am unsure how to do this.

I'd like to create something similar to a DropBox or OneDrive folder.

Something like this -

Something like this

I've looked at the Manipulating the Windows 7 Explorer navigation pane question but I don't think its what I want. The application will run on machines with Windows 7 to Windows 10. Is it possible to do this on all these OS?

Any help would be greatly appreciated.

Community
  • 1
  • 1
Belothian
  • 165
  • 3
  • 9
  • possible duplicate of [How to programmatically add a folder to Favorites in Windows File Explorer](http://stackoverflow.com/questions/16656342) or [How do I programmatically add a folder to the user's Favorites (in Windows Explorer)?](http://stackoverflow.com/questions/4271759) – Jonathon Reinhart May 21 '14 at 08:27
  • possible duplicate of [How to programmatically add a folder to Favorites in Windows File Explorer](http://stackoverflow.com/questions/16656342/how-to-programmatically-add-a-folder-to-favorites-in-windows-file-explorer) – Paddy May 21 '14 at 09:16
  • Not an intentional duplicate, but thanks both of these seem to point me in right direction, although I not necessarily a short-cut to a folder, but its a means to an end! – Belothian May 21 '14 at 09:29
  • http://stackoverflow.com/questions/30051634/is-it-possible-programmatically-add-folders-to-the-windows-10-quick-access-panel – jsanalytics Jan 04 '16 at 06:07
  • Looks like you want a custom Shell Extension. This job is for C++ rather than C# https://msdn.microsoft.com/en-us/library/cc144095(v=vs.85).aspx#unknown_61377, although there are some materials how to implement it in C#, here is one of them: http://www.codeproject.com/Articles/3551/C-does-Shell-Part (or google "ishellfolder c#") – vzayko Jan 04 '16 at 07:42
  • Do you have a physical folder that you want to point to, or is this all virtual? – Simon Mourier Jan 04 '16 at 09:30
  • @Simon, Yes I have it physically. The root folder will be on the local machine deep inside and will have subfolders. The root folder should show up in the pane. – Mangesh Jan 04 '16 at 13:56

3 Answers3

14

This is partially documented in this document : Integrate a Cloud Storage Provider although the title is misleading; it works for regular folders. Also, it works fine on Windows 7, Windows 8.x, and 10.

So, here is the content of a .BAT file (using the standard reg.exe tool, but you can easily replace this by C# code) that can create a folder like OneDrive. First you must create a Guid by any means, replace the "MyExt" name by your folder's display name, the "c:\temp\myext" path by any physical path, and then run this .bat file.

reg add HKCU\Software\Classes\CLSID\{YOURGUID-GOES-HERE-0000-000000000000} /ve /t REG_SZ /d "MyExt" /f
reg add HKCU\Software\Classes\CLSID\{YOURGUID-GOES-HERE-0000-000000000000}\DefaultIcon /ve /t REG_EXPAND_SZ /d %%SystemRoot%%\system32\imageres.dll,-111 /f
reg add HKCU\Software\Classes\CLSID\{YOURGUID-GOES-HERE-0000-000000000000} /v System.IsPinnedToNameSpaceTree /t REG_DWORD /d 0x1 /f
reg add HKCU\Software\Classes\CLSID\{YOURGUID-GOES-HERE-0000-000000000000} /v SortOrderIndex /t REG_DWORD /d 0x42 /f
reg add HKCU\Software\Classes\CLSID\{YOURGUID-GOES-HERE-0000-000000000000}\InProcServer32 /ve /t REG_EXPAND_SZ /d %%systemroot%%\system32\shell32.dll /f
reg add HKCU\Software\Classes\CLSID\{YOURGUID-GOES-HERE-0000-000000000000}\Instance /v CLSID /t REG_SZ /d {0E5AAE11-A475-4c5b-AB00-C66DE400274E} /f
reg add HKCU\Software\Classes\CLSID\{YOURGUID-GOES-HERE-0000-000000000000}\Instance\InitPropertyBag /v Attributes /t REG_DWORD /d 0x11 /f
reg add HKCU\Software\Classes\CLSID\{YOURGUID-GOES-HERE-0000-000000000000}\Instance\InitPropertyBag /v TargetFolderPath /t REG_EXPAND_SZ /d "c:\temp\myext" /f
reg add HKCU\Software\Classes\CLSID\{YOURGUID-GOES-HERE-0000-000000000000}\ShellFolder /v FolderValueFlags /t REG_DWORD /d 0x28 /f
reg add HKCU\Software\Classes\CLSID\{YOURGUID-GOES-HERE-0000-000000000000}\ShellFolder /v Attributes /t REG_DWORD /d 0xF080004D /f
reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\{YOURGUID-GOES-HERE-0000-000000000000} /ve /t REG_SZ /d "MyExt" /f
reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel /v {YOURGUID-GOES-HERE-0000-000000000000} /t REG_DWORD /d 0x1 /f

Note this will register the folder for the current user (so you don't need special rights in the registry), but if you want to register it for the whole machine, you'll have to replace HKCU by HKLM (and you'll need proper rights then).

Also note I've chosen a default icon in imageres.dll but you can use anything else of course.

This is how it looks like on Windows 10: enter image description here


To remove the folder from the pane, create another .BAT file with the following content:

reg delete HKCU\Software\Classes\CLSID\{YOURGUID-GOES-HERE-0000-000000000000}
reg delete HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\{YOURGUID-GOES-HERE-0000-000000000000}
reg delete HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel
Mangesh
  • 5,491
  • 5
  • 48
  • 71
Simon Mourier
  • 132,049
  • 21
  • 248
  • 298
  • Any idea about `Windows 10`? – Mangesh Jan 06 '16 at 05:18
  • This is not working for `OpenFileDialog` (ideally, it should). Is any there any extra entry for that? – Mangesh Jan 25 '16 at 09:07
  • Here on 8.1, it is working only for some dialogs. For example, if I open the dialog from Word then it shows up but if, it is from VS, it doesn't. – Mangesh Jan 26 '16 at 08:57
  • 1
    Ok, yes, apps can use flags when they call these dialogs. These flags can exclude/include folders depending on how they are defined (for example see FILEOPENDIALOGOPTIONS::FOS_FORCEFILESYSTEM or FOS_ALLNONSTORAGEITEMS). There is not much you can do, however you can try to play with the ShellFolder\Attributes value maps to https://msdn.microsoft.com/en-us/library/windows/desktop/bb762589.aspx – Simon Mourier Jan 26 '16 at 09:14
  • 2
    Note: this does not work on Windows 7. E.g. dropbox does not even try to create this icon on Windows 7. – daliusd Oct 12 '17 at 10:24
  • I can confirm that this does not work on Windows 7. Even Google Drive won't try to achieve this, instead it creates an entry under favorites. Here is a MSDN page stating that: [Integrating your cloud storage provider is only supported starting in Windows 10](https://learn.microsoft.com/en-us/windows/desktop/shell/integrate-cloud-storage) – Amir Mahdi Nassiri Aug 21 '18 at 09:55
  • Has anyone used the link posted by Simon Mourier to be able to get a folder created this way to appear in File-Open dialog boxes of applications like Word, Excel, or others? – Bret Thompson Jan 20 '22 at 22:53
  • @BretThompson - Just use my code and it should work fine: https://i.imgur.com/9DNIxNl.png or ask another question with more details – Simon Mourier Jan 21 '22 at 06:35
  • Thank you for responding Simon Mourier. I did use your code posted above, and the shell folder is showing up and working in File Explorer and in the Open/Save dialog boxes of many applications. But it will not show up in Microsoft applications, including all the Office applications and Visual Studio 2019. Acrobat Reader also will not see it. I am on Windows 10. – Bret Thompson Jan 21 '22 at 12:44
  • @BretThompson - as you see in the image, it works fine for me in Word (and any application in fact), I'm also on Windows 10. – Simon Mourier Jan 21 '22 at 13:30
  • @BretThompson - it's probably because you're using 32-bit versions of programs (Adobe, Office, etc.). 64-bit versions should work fine. – Simon Mourier Jan 21 '22 at 17:20
  • 1
    @SimonMourier, you are correct. The solution for this was to duplicate the first 10 lines of your code and add the subfolder of "WOW6432Node" between "Classes" and "CLSID". This second set of registry entries made the folder visible in the 32 bit software's. – Bret Thompson Jan 21 '22 at 21:03
8

Here is a C# code to add Shell Folder for current user. If you want to add it for local machine, change RegistryHive.CurrentUser to RegistryHive.LocalMachine (you will need elevated access in this case).

To add the Shell Folder:

void fnCreateShellFolder(string strGUID, string strFolderTitle, string strTargetFolderPath, string strIconPath)
{
    RegistryKey localKey, keyTemp, rootKey;
    if (Environment.Is64BitOperatingSystem)
        localKey = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64);
    else
        localKey = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry32);

    rootKey = localKey.CreateSubKey(@"Software\Classes\CLSID\{" + strGUID + "}");
    rootKey.SetValue("", strFolderTitle, RegistryValueKind.String);
    rootKey.SetValue("System.IsPinnedToNameSpaceTree", unchecked((int)0x1), RegistryValueKind.DWord);
    rootKey.SetValue("SortOrderIndex", unchecked((int)0x42), RegistryValueKind.DWord);

    keyTemp = rootKey.CreateSubKey(@"DefaultIcon");
    keyTemp.SetValue("", strIconPath, RegistryValueKind.ExpandString);
    keyTemp.Close();

    keyTemp = rootKey.CreateSubKey(@"InProcServer32");
    keyTemp.SetValue("", @"%systemroot%\system32\shell32.dll", RegistryValueKind.ExpandString);
    keyTemp.Close();

    keyTemp = rootKey.CreateSubKey(@"Instance");
    keyTemp.SetValue("CLSID", "{0E5AAE11-A475-4c5b-AB00-C66DE400274E}", RegistryValueKind.String);
    keyTemp.Close();

    keyTemp = rootKey.CreateSubKey(@"Instance\InitPropertyBag");
    keyTemp.SetValue("Attributes", unchecked((int)0x11), RegistryValueKind.DWord);
    keyTemp.SetValue("TargetFolderPath", strTargetFolderPath, RegistryValueKind.ExpandString);
    keyTemp.Close();

    keyTemp = rootKey.CreateSubKey(@"ShellFolder");
    keyTemp.SetValue("FolderValueFlags", unchecked((int)0x28), RegistryValueKind.DWord);
    keyTemp.SetValue("Attributes", unchecked((int)0xF080004D), RegistryValueKind.DWord);
    keyTemp.Close();
    rootKey.Close();

    keyTemp = localKey.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\{" + strGUID + "}");
    keyTemp.SetValue("", strFolderTitle, RegistryValueKind.String);
    keyTemp.Close();

    keyTemp = localKey.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel");
    keyTemp.SetValue("{" + strGUID + "}", unchecked((int)0x1), RegistryValueKind.DWord);
    keyTemp.Close();
}

To remove the Shell Folder:

static void fnRemoveShellFolder(string strGUID)
{
    RegistryKey localKey;
    if (Environment.Is64BitOperatingSystem)
        localKey = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64);
    else
        localKey = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry32);

    localKey.DeleteSubKeyTree(@"Software\Classes\CLSID\{" + strGUID + "}", false);
    localKey.DeleteSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\{" + strGUID + "}", false);
    localKey.DeleteSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel", false);
}

You may need to restart the explorer to see the changes.

// restart explorer
foreach (System.Diagnostics.Process exe in System.Diagnostics.Process.GetProcesses())
    if (exe.ProcessName == "explorer")
        exe.Kill();
Mangesh
  • 5,491
  • 5
  • 48
  • 71
  • 1
    These registry settings have some problems I guess. When I call the fnRemoveShellFolder of yours, desktop icons such as "Computer", "Control Panel" and "User" get removed too. Even they got unchecked from the "Desktop Icon Settings". – Amir Mahdi Nassiri Jan 15 '18 at 12:27
  • This needs to be put into a library to be called as a shell extension so a user can right-click any folder and select "Pin to Navigation" – The Sharp Ninja Nov 06 '19 at 06:31
6

I changed a single line of Mangesh's code, and now everything works just fine. Because when I called the fnRemoveShellFolder of Mangesh's, desktop icons such as "Computer", "Control Panel" and "User" get removed too. Even they got unchecked from the "Desktop Icon Settings".

localKey.DeleteSubKeyTree(@"Software\Classes\CLSID\{" + GUID + "}", false);
localKey.DeleteSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\{" + GUID + "}", false);
tempKey = localKey.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel", true);
tempKey.DeleteValue("{" + GUID + "}", false);
Amir Mahdi Nassiri
  • 1,190
  • 13
  • 21