2013-6-20-公共用户桌面和用户桌面

1.获取用户桌面及其桌面的所有东西
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);


            DirectoryInfo di = new DirectoryInfo(path);
            FileInfo[] files = di.GetFiles();//files包含了用户桌面(当前用户的桌面)的所有东西




2.获取公共用户桌面及其桌面的所有东西
调用C++的函数:


[DllImport("shfolder.dll", CharSet = CharSet.Auto)]
private static extern int SHGetFolderPath ( IntPtr hwndOwner, int nFolder, IntPtr hToken, int dwFlags, StringBuilder 


lpszPath );
private const int MAX_PATH = 260;
private const int CSIDL_COMMON_DESKTOPDIRECTORY = 0x0019;
public static string GetAllUsersDesktopFolderPath ( )
{
     StringBuilder sbPath = new StringBuilder(MAX_PATH);
     SHGetFolderPath(IntPtr.Zero, CSIDL_COMMON_DESKTOPDIRECTORY, IntPtr.Zero, 0, sbPath);
     return sbPath.ToString();
}

你可能感兴趣的:(C++,WinForm)