using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; namespace CsWindowsDirectory { class Program { [DllImport("kernel32", CharSet = CharSet.Auto)] private static extern uint GetWindowsDirectory(string buffer, uint length); //Windowsディレクトリを取得する public static string GetWindowsDirectoryPath() { string buf = new string(' ', 260); uint len = GetWindowsDirectory(buf, 260); return buf.Substring(0, (int)len); } static void Main(string[] args) { Console.WriteLine(GetWindowsDirectoryPath()); } } }