如何以编程方式添加到用户的收藏夹文件夹(在Windows资源管理器)? [英] How do I programmatically add a folder to the user's Favorites (in Windows Explorer)?

查看:261
本文介绍了如何以编程方式添加到用户的收藏夹文件夹(在Windows资源管理器)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找一种方式将文件夹添加编程方式在Windows资源管理器的收藏夹。它的Windows资源管理器的具体和围绕这个项目:的http:/ /www.codeproject.com/Tips/132804/Open-folders-using-a-Run-Command



到目前为止,我已经试过进程监视器和搜索注册表,但我似乎无法找到我的Windows资源管理器收藏夹中的注册表编辑器





微软在Windows 8中改变了这种所以我相应标记我的问题。请参阅在Win8中和放标记答案的意见; 。等等细节


解决方案

PS:请一定要看看< A HREF =htt​​p://stackoverflow.com/a/7492325/240733> @bsegraves的解决方案,我认为这是远远比我的好。




我不知道如果这是你在找什么,但我认为最喜欢的文件夹,可以通过以下注册表值中找到:

  HKEY_CURRENT_USER\ 
Software\
Microsoft\
Windows\
CurrentVersion\
浏览器\
的用户壳牌Folders\
收藏夹

您应该能够用下面的代码获取该文件夹的名称:

 使用的Microsoft.Win32; 
...

的RegistryKey TOPLEVEL = Registry.CurrentUser;
的RegistryKey键= topLevel.OpenSubKey(
@Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell文件夹,
真);

串favoriteFolder = key.GetValue(最爱)的ToString();



这是那么只创建一个链接或文件,在指定的文件夹中的一个问题。



(请注意,这个键的值可能是这样的%USERPROFILE%\Favorites ;环境变量应自动得到扩展通过上面援引的 .GetValue(..)的方法。)


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

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 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.

解决方案

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.

(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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆