Dec 1, 2018 07:21 AM
(This post was last modified: Dec 1, 2018 05:55 PM by gigajew.)
Here's a snippet to get the Windows directory using the Windows API. Easy to use.
Code
[DllImport("kernel32.dll", BestFitMapping = true, CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.U4)]
private static extern uint GetWindowsDirectory(StringBuilder builder, [MarshalAs(UnmanagedType.U4)] uint size);
private static DirectoryInfo GetWindowsDirectory()
{
StringBuilder builder = new StringBuilder(260);
uint realLength = GetWindowsDirectory( builder, (uint)builder.Capacity);
string windowsDir = builder.ToString();
return new DirectoryInfo(windowsDir);
}![[Image: Syr3DlV.png]](https://i.imgur.com/Syr3DlV.png)


