如何以编程方式将文件夹添加到用户的收藏夹(在 Windows 资源管理器中)?

How do I programmatically add a folder to the user#39;s Favorites (in Windows Explorer)?(如何以编程方式将文件夹添加到用户的收藏夹(在 Windows 资源管理器中)?)
本文介绍了如何以编程方式将文件夹添加到用户的收藏夹(在 Windows 资源管理器中)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种以编程方式将文件夹添加到 Windows 资源管理器中的收藏夹的方法.它的 Windows Explorer 特定并基于此项目:http:///www.codeproject.com/Tips/132804/Open-folders-using-a-Run-Command

I am looking for a way to programmatically add a folder to the Favorites in Windows Explorer. Its Windows Explorer specific and based around this project: http://www.codeproject.com/Tips/132804/Open-folders-using-a-Run-Command

到目前为止,我已经尝试过 Process Monitor 并搜索注册表,但我似乎无法在 regedit 中找到我的 Windows Explorer 收藏夹.

So far I've tried Process Monitor and searching the registry, but I can't seem to find my Windows Explorer Favourites in regedit.

<小时>Microsoft 在 Windows 8 中对此进行了更改,因此我相应地标记了我的问题.请参阅 Win8 & 的标记答案中的评论等细节.


Microsoft has changed this in Windows 8 so I have tagged my question accordingly. Please see the comments in the marked answer for Win8 & etc details.

推荐答案

PS:请务必查看 @bsegraves' 解决方案,我认为这是比我的好多了.

P.S.: Make sure to check out @bsegraves' solution, which I think is far better than mine.

我不确定这是否是您要查找的内容,但我认为可以通过以下注册表值找到最喜欢的文件夹:

I'm not sure if this is what you're looking for, but I think the favorite folder can be found through the following registry value:

HKEY_CURRENT_USER
  Software
    Microsoft
      Windows
        CurrentVersion
          Explorer
            User Shell Folders
              Favorites

您应该能够使用以下代码检索此文件夹名称:

You should be able to retrieve this folder name with the following code:

using Microsoft.Win32;
...

RegistryKey topLevel = Registry.CurrentUser;
RegistryKey key = topLevel.OpenSubKey(
    @"SoftwareMicrosoftWindowsCurrentVersionExplorerUser Shell Folders",
    true);

string favoriteFolder = key.GetValue("Favorites").ToString();

然后只需在指定文件夹中创建链接或文档即可.

It's then only a matter of creating a link, or document, in the specified folder.

(请注意,此键的值可能类似于 %USERPROFILE%Favorites;环境变量应由 .GetValue(..) 方法自动扩展上面调用过.)

(Take note that this key's value might be something like %USERPROFILE%Favorites; the environment variable should automatically get expanded by the .GetValue(..) method invoked above.)

这篇关于如何以编程方式将文件夹添加到用户的收藏夹(在 Windows 资源管理器中)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)