首页 > 编程语言 >C#读取“我的文档”等特殊系统路径及环境变量

C#读取“我的文档”等特殊系统路径及环境变量

时间:2023-01-08 12:33:23浏览次数:38  
标签:folders string C# 路径 GetValue Windows ToString 文档 环境变量

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;
        }
    }

 

标签:folders,string,C#,路径,GetValue,Windows,ToString,文档,环境变量
From: https://www.cnblogs.com/firstcsharp/p/17034397.html

相关文章

  • DevOps实战系列【第五章】:基于Gitlab/Maven/Jenkins/Docker实战案例详解
    个人亲自录制全套DevOps系列实战教程:​​手把手教你玩转DevOps全栈技术​​从创建Jenkins的job开始1.gitlab设置:我们从新建一个jenkins任务开始,建一个自由风格项目,我们暂时......
  • 初学者难点:如何在C语言中打印小数???
       首先对于我自己而言,刚刚学习C语言的时候一直弄不清楚如何打印小数,尤其是打印两位或者三位小数,当时只会打印整数,也就导致后来一直被蒙在鼓里。下面是我在弄清楚如何......
  • linux上ifconfig命令详解
    1.ifconfig简介2.用法3.参数说明3.1.选项介绍3.2.硬件类型3.3.地址族列表3.3.1.说明4.示例4.1.示例1:如何重启网卡?4.2.示例2:配置网卡en......
  • 【C#】记ArcObject下的几何投影变换的一个需要注意的坑
    翻出陈年代码重写,老是报”Thecoordinatesormeasuresareoutofbounds.“找来找去发现错误出在下面snippet里,geometry.Project(spatialReferenceTo)会对传入的point处......
  • 【博学谷学习记录】超强总结,用心分享|CSS布局知识总结
    CSS布局一、浮动1.1结构伪类选择器1.作用与优势:作用:根据元素在HTML中的结构关系查找元素优势:减少HTML中类的依赖,有利于保持代码整洁场景:常用于查找某父级选择器中......
  • 【优先队列】LeetCode 347. 前 K 个高频元素
    题目链接347.前K个高频元素思路前k大模板题代码classSolution{publicint[]topKFrequent(int[]nums,intk){PriorityQueue<Map.Entry<Integer,......
  • Educational Codeforces Round 14
    EducationalCodeforcesRound14https://codeforces.com/contest/6914/6:ABCD(C是恶心人的模拟分类讨论,写了巨久导致没时间看EF)这场没有红题,应该是可以补完的。A.Fas......
  • anaconda基本操作及一些问题的解决记录
    anaconda虚拟环境查看安装了哪些包condalist查看当前存在哪些虚拟环境condaenvlistcondainfo-e检查更新当前condacondaupdatecondaPython创建虚......
  • Fiddlercore
    Fiddlercore拦截并修改HTTPS链接的网页,实现JS注入.联系QQ564955427 https://www.cnblogs.com/Charltsing/p/FiddlerCoreHTTPS.html使用fiddlercore修改网页的返回内容h......
  • re | [QCTF2018]Xman-babymips
    re|[QCTF2018]Xman-babymipsmips32架构的题目位运算,前5位直接xor,后面再加密一次。直接爆破就好exp:aim=[82,253,22,164,137,189,146,128,19,65,84,16......