I\'ve looked at the Environment.GetFolderPath method and the System.Environment.SpecialFolder enum but I couldn\'t see anything that returns the path of the Default Users fo
Snippet from LINQPad (Language: C# Program) that outputs 'C:\Users\Default\Desktop':
void Main()
{
GetFolderPath(Environment.SpecialFolder.Desktop).Dump();
}
// Define other methods and classes here
[DllImport("shfolder.dll", CharSet=CharSet.Auto)]
internal static extern int SHGetFolderPath(IntPtr hwndOwner, int nFolder, int hToken, int dwFlags, StringBuilder lpszPath);
public static string GetFolderPath(Environment.SpecialFolder folder)
{
if (!Enum.IsDefined(typeof(Environment.SpecialFolder), folder))
{
throw new Exception("Crap");
}
StringBuilder lpszPath = new StringBuilder(260);
SHGetFolderPath(IntPtr.Zero, (int) folder, -1, 0, lpszPath);
string path = lpszPath.ToString();
new FileIOPermission(FileIOPermissionAccess.PathDiscovery, path).Demand();
return path;
}
Edit: I had the following imports in LINQPad
System.Runtime.InteropServices
System.Globalization
System.Security.Permissions
I used reflector to look at Environment.GetFolderPath
and then took a look at SHGetFolderPath
that specifies by passing -1 as hToken you get Default User instead.