Windows - 将带有子目录的目录添加到左侧导航窗格

时间:2016-09-10 15:45:22

标签: c# windows registry sidebar

我想在左侧导航窗格中添加目录节点。它应包含实际位于文件系统上的子目录的链接。 Currenty它只显示“Test”下最后一个注册路径的内容。 我说明了问题:左侧是当前状态。右侧(蒙太奇照片)是我期待它的方式。 f

这是可能的还是我必须链接到我将符号链接添加到目标目录的目录?

这就是我到目前为止所做的事情(基本上来自类似的SO问题和“集成云存储提供商”Windows帮助页面):

class Program
    {
        static void Main(string[] args)
        {
            string[] defaultFolders = { "C:\\Intel\\Logs", "C:\\Python27" };
            var sm = new ShellextensionManger();
            var guid = Guid.Parse("{03d6d437-c11c-49fc-9dcd-aa65e15b77ea}");
            sm.createShellFolder(guid.ToString(), "Test", defaultFolders, "C:\\icon.ico");
            sm.removeShellFolder(guid.ToString());
        }
    }

internal class ShellextensionManger
    {
        private const uint SORT_ORDER_VERY_TOP = 1;

        public ShellextensionManger() {}

        public void createShellFolder(string strGUID, string strFolderTitle, IEnumerable<string> strTargetFolderPaths, string strIconPath)
        {
            RegistryKey localKey, keyTemp, rootKey;
            localKey = getRegistryKeyArcgIndependent(RegistryHive.CurrentUser);

            // Add your CLSID and name your extension
            rootKey = localKey.CreateSubKey(@"Software\Classes\CLSID\{" + strGUID + "}");
            rootKey.SetValue("", strFolderTitle, RegistryValueKind.String);
            // Add your extension to the Navigation Pane and make it visible
            rootKey.SetValue("System.IsPinnedToNameSpaceTree", unchecked((int)0x1), RegistryValueKind.DWord);
            // Set the location for your extension in the Navigation Pane
            rootKey.SetValue("SortOrderIndex", unchecked((int) SORT_ORDER_VERY_TOP), RegistryValueKind.DWord);

            // Set the image for your icon
            keyTemp = rootKey.CreateSubKey(@"DefaultIcon");
            keyTemp.SetValue("", strIconPath, RegistryValueKind.ExpandString);
            keyTemp.Close();

            // Provide the dll that hosts your extension.
            keyTemp = rootKey.CreateSubKey(@"InProcServer32");
            keyTemp.SetValue("", @"%systemroot%\system32\shell32.dll", RegistryValueKind.ExpandString);
            keyTemp.Close();

            /*
             * Define the instance object
             * Indicate that your namespace extension should function like other file folder structures in File Explorer. For more information about shell instance objects, see Creating Shell Extensions with Shell Instance Objects.
             */
            keyTemp = rootKey.CreateSubKey(@"Instance");
            keyTemp.SetValue("CLSID", "{0E5AAE11-A475-4c5b-AB00-C66DE400274E}", RegistryValueKind.String);
            keyTemp.Close();


            foreach (String path in strTargetFolderPaths) {
                keyTemp = rootKey.CreateSubKey(@"Instance\InitPropertyBag");
                // Provide the file system attributes of the target folder
                keyTemp.SetValue("Attributes", unchecked((int) (FileAttributes.Directory & FileAttributes.ReadOnly)), RegistryValueKind.DWord);
                // Set the path for the sync root
                keyTemp.SetValue("TargetFolderPath", path, RegistryValueKind.ExpandString);
                keyTemp.Close();
            }

            // Set appropriate shell flags
            keyTemp = rootKey.CreateSubKey(@"ShellFolder");
            keyTemp.SetValue("FolderValueFlags", unchecked((int)0x28), RegistryValueKind.DWord);
            // Set the appropriate flags to control your shell behavior
            keyTemp.SetValue("Attributes", unchecked((int)0xF080004D), RegistryValueKind.DWord);
            keyTemp.Close();
            rootKey.Close();

            // Register your extension in the namespace root
            keyTemp = localKey.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\{" + strGUID + "}");
            keyTemp.SetValue("", strFolderTitle, RegistryValueKind.String);
            keyTemp.Close();

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

        public void removeShellFolder(string strGUID)
        {
            RegistryKey localKey;
            localKey = getRegistryKeyArcgIndependent(RegistryHive.CurrentUser);

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

        private RegistryKey getRegistryKeyArcgIndependent(RegistryHive registryHive) {
            RegistryView registryView = Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32;
            return RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, registryView);
        }
    }

请注意,我在主页末尾删除了该条目以进行调试。如果您尝试代码,请设置断点。

0 个答案:

没有答案