如何以编程方式将文件夹添加到用户的收藏夹(在Windows资源管理器中)? [英] How do I programmatically add a folder to the user's Favorites (in Windows Explorer)?
问题描述
我正在寻找一种以编程方式将文件夹添加到Windows资源管理器中的收藏夹"中的方法.它的Windows资源管理器特定于此项目,并且基于该项目: 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资源管理器收藏夹.
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(
@"Software\Microsoft\Windows\CurrentVersion\Explorer\User 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资源管理器中)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!