I'm using .NET 2.0. I noticed that there doesn't seem to be a Environment.SpecialFolder member for the common Desktop and common Start Menu folders.
i would prefer a way that doesn't involve loading shell32.dll and using SHGetSpecialFolderPath
This code snippet uses the registry to access the common desktop:
Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine;
key = key.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders");
String commonDesktop = key.GetValue("Common Desktop").ToString();
From here
I use P/Invoke... 0x19 corresponds to the Common Desktop enumeration, 0x16 corresponds to the Common Start Menu
public static string GetCommonDesktopFolder()
{
var sb = new StringBuilder(260);
SHGetFolderPath(IntPtr.Zero, 0x19, IntPtr.Zero, 0, sb); // CSIDL_COMMON_DESKTOPDIRECTORY
return sb.ToString();
}
[DllImport("shell32.dll")]
private static extern int SHGetFolderPath(
IntPtr hwndOwner, int nFolder, IntPtr hToken,
uint dwFlags, StringBuilder pszPath);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With