C#获得特殊路径

using Microsoft.Win32;

02. namespace JPGCompact
03. {
04.     public partial class MainForm : Form
05.     {
06.         private void Test()
07.         {
08.             RegistryKey folders;
09.             folders = OpenRegistryPath(Registry.CurrentUser, @"/software/microsoft/windows/currentversion/explorer/shell folders");
10.             // Windows用户桌面路径
11.             string desktopPath = folders.GetValue("Desktop").ToString();
12.             // Windows用户字体目录路径
13.             string fontsPath = folders.GetValue("Fonts").ToString();
14.             // Windows用户网络邻居路径
15.             string nethoodPath = folders.GetValue("Nethood").ToString();
16.             // Windows用户我的文档路径
17.             string personalPath = folders.GetValue("Personal").ToString();
18.             // Windows用户开始菜单程序路径
19.             string programsPath = folders.GetValue("Programs").ToString();
20.             // Windows用户存放用户最近访问文档快捷方式的目录路径
21.             string recentPath = folders.GetValue("Recent").ToString();
22.             // Windows用户发送到目录路径
23.             string sendtoPath = folders.GetValue("Sendto").ToString();
24.             // Windows用户开始菜单目录路径
25.             string startmenuPath = folders.GetValue("Startmenu").ToString();
26.             // Windows用户开始菜单启动项目录路径
27.             string startupPath = folders.GetValue("Startup").ToString();
28.             // Windows用户收藏夹目录路径
29.             string favoritesPath = folders.GetValue("Favorites").ToString();
30.             // Windows用户网页历史目录路径
31.             string historyPath = folders.GetValue("History").ToString();
32.             // Windows用户Cookies目录路径
33.             string cookiesPath = folders.GetValue("Cookies").ToString();
34.             // Windows用户Cache目录路径
35.             string cachePath = folders.GetValue("Cache").ToString();
36.             // Windows用户应用程式数据目录路径
37.             string appdataPath = folders.GetValue("Appdata").ToString();
38.             // Windows用户打印目录路径
39.             string printhoodPath = folders.GetValue("Printhood").ToString();
40.         }
41.   
42.         private RegistryKey OpenRegistryPath(RegistryKey root, string s)
43.         {
44.             s = s.Remove(0, 1) + @"/";
45.             while (s.IndexOf(@"/") != -1)
46.             {
47.                 root = root.OpenSubKey(s.Substring(0, s.IndexOf(@"/")));
48.                 s = s.Remove(0, s.IndexOf(@"/") + 1);
49.             }
50.             return root;
51.         }
52.     }
53. }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值