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.}
本文介绍了一种使用C#和Windows注册表API来获取Windows系统中特定用户文件夹路径的方法,包括桌面、文档等常见位置。
288

被折叠的 条评论
为什么被折叠?



