C#读取“我的文档”等特殊系统路径及环境变量
using Microsoft.Win32; namespace JPGCompact { public partial class MainForm : Form { private void Test() { RegistryKey folders; folders = OpenRegistryPath(Registry.CurrentUser, @"\software\microsoft\windows\currentversion\explorer\shell folders"); // Windows用户桌面路径 string desktopPath = folders.GetValue("Desktop").ToString(); // Windows用户字体目录路径 string fontsPath = folders.GetValue("Fonts").ToString(); // Windows用户网络邻居路径 string nethoodPath = folders.GetValue("Nethood").ToString(); // Windows用户我的文档路径 string personalPath = folders.GetValue("Personal").ToString(); // Windows用户开始菜单程序路径 string programsPath = folders.GetValue("Programs").ToString(); // Windows用户存放用户最近访问文档快捷方式的目录路径 string recentPath = folders.GetValue("Recent").ToString(); // Windows用户发送到目录路径 string sendtoPath = folders.GetValue("Sendto").ToString(); // Windows用户开始菜单目录路径 string startmenuPath = folders.GetValue("Startmenu").ToString(); // Windows用户开始菜单启动项目录路径 string startupPath = folders.GetValue("Startup").ToString(); // Windows用户收藏夹目录路径 string favoritesPath = folders.GetValue("Favorites").ToString(); // Windows用户网页历史目录路径 string historyPath = folders.GetValue("History").ToString(); // Windows用户Cookies目录路径 string cookiesPath = folders.GetValue("Cookies").ToString(); // Windows用户Cache目录路径 string cachePath = folders.GetValue("Cache").ToString(); // Windows用户应用程式数据目录路径 string appdataPath = folders.GetValue("Appdata").ToString(); // Windows用户打印目录路径 string printhoodPath = folders.GetValue("Printhood").ToString(); } private RegistryKey OpenRegistryPath(RegistryKey root, string s) { s = s.Remove(0, 1) + @"\"; while (s.IndexOf(@"\") != -1) { root = root.OpenSubKey(s.Substring(0, s.IndexOf(@"\"))); s = s.Remove(0, s.IndexOf(@"\") + 1); } return root; } }
微信号:jamesworkshop 学习QQ群:364976091
分类:
C#基础
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2019-01-08 Vim 保存和退出命令
2019-01-08 CentOS下防御或减轻DDoS攻击方法(转)
2019-01-08 CentOS 7 firewalld vsftpd开放端口
2019-01-08 CentOS7使用firewalld打开关闭防火墙与端口
2015-01-08 jquery 删除字符串最后一个字符的方法
2015-01-08 jQuery中.html(“xxx”)和.append("xxx")的区别和不同
2015-01-08 Jquery中对checkbox的各种“全选”或者“取消”功能实现(特别注意1.6+的一定不能使用attr来取属性了!用prop!)