private void InitVars() { IntPtr tempPidl; ShellAPI.SHFILEINFO info; //My Computer info = new ShellAPI.SHFILEINFO(); tempPidl = IntPtr.Zero; ShellAPI.SHGetSpecialFolderLocation(IntPtr.Zero, ShellAPI.CSIDL.DRIVES, out tempPidl); ShellAPI.SHGetFileInfo(tempPidl, 0, ref info, ShellAPI.cbFileInfo, ShellAPI.SHGFI.PIDL | ShellAPI.SHGFI.DISPLAYNAME | ShellAPI.SHGFI.TYPENAME); sysfolderName = info.szTypeName; mycompName = info.szDisplayName; Marshal.FreeCoTaskMem(tempPidl); // //Dekstop tempPidl = IntPtr.Zero; ShellAPI.SHGetSpecialFolderLocation(IntPtr.Zero, ShellAPI.CSIDL.DESKTOP, out tempPidl); IntPtr desktopFolderPtr; ShellAPI.SHGetDesktopFolder(out desktopFolderPtr); desktopItem = new ShellItem(this, tempPidl, desktopFolderPtr); // //My Documents uint pchEaten = 0; ShellAPI.SFGAO pdwAttributes = 0; desktopItem.ShellFolder.ParseDisplayName( IntPtr.Zero, IntPtr.Zero, "::{450d8fba-ad25-11d0-98a8-0800361b1103}", ref pchEaten, out tempPidl, ref pdwAttributes); info = new ShellAPI.SHFILEINFO(); ShellAPI.SHGetFileInfo(tempPidl, 0, ref info, ShellAPI.cbFileInfo, ShellAPI.SHGFI.PIDL | ShellAPI.SHGFI.DISPLAYNAME); mydocsName = info.szDisplayName; Marshal.FreeCoTaskMem(tempPidl); StringBuilder path = new StringBuilder(ShellAPI.MAX_PATH); ShellAPI.SHGetFolderPath( IntPtr.Zero, ShellAPI.CSIDL.PERSONAL, IntPtr.Zero, ShellAPI.SHGFP.TYPE_CURRENT, path); mydocsPath = path.ToString(); // }
public static int GetSpecialFolderImageIndex(ShellAPI.CSIDL pidl) { IntPtr tempPidl = IntPtr.Zero; ShellAPI.SHGetSpecialFolderLocation(IntPtr.Zero, pidl, out tempPidl); ShellAPI.SHFILEINFO shfiSmall = new ShellAPI.SHFILEINFO(); ShellAPI.SHGetFileInfo(tempPidl, 0, ref shfiSmall, ShellAPI.cbFileInfo, ShellAPI.SHGFI.PIDL | ShellAPI.SHGFI.ICON | ShellAPI.SHGFI.SMALLICON | ShellAPI.SHGFI.SYSICONINDEX ); return(shfiSmall.iIcon); }