Belothian
Belothian

Reputation: 165

Pin a folder to Navigation Pane in Windows Explorer

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.

Upvotes: 10

Views: 6137

Answers (3)

Simon Mourier
Simon Mourier

Reputation: 138841

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

Upvotes: 15

Amir Mahdi Nassiri
Amir Mahdi Nassiri

Reputation: 1330

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);

Upvotes: 6

Mangesh
Mangesh

Reputation: 5841

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();

Upvotes: 8

Related Questions