获取各种系统目录

下面的示例演示如何将 Environment.SpecialFolder 与方法结合使用 Environment.GetFolderPath 来获取系统目录。

// Sample for the Environment.GetFolderPath method
using System;

class Sample
{
    public static void Main()
    {
    Console.WriteLine();
    Console.WriteLine("GetFolderPath: {0}",
                 Environment.GetFolderPath(Environment.SpecialFolder.System));
    }
}

Windows 目录或 SYSROOT。 它与 %windir% 或 %SYSTEMROOT% 环境变量相对应。

//获取当前系统磁盘符方法1,返回:C:
string path = Environment.GetEnvironmentVariable("systemdrive");
//获取当前系统磁盘符方法2,返回:C:
string path1 = Environment.ExpandEnvironmentVariables("%systemdrive%");
// 系统所安装的路径
Environment.GetEnvironmentVariable("windir");

  

https://docs.microsoft.com/zh-cn/dotnet/api/system.environment.specialfolder?redirectedfrom=MSDN&view=net-5.0

原文地址:https://www.cnblogs.com/wzihan/p/14750990.html