C# 在Windows Vista上获取默认用户帐户配置文件图片>;8.

C# 在Windows Vista上获取默认用户帐户配置文件图片>;8.,c#,.net,windows,winforms,C#,.net,Windows,Winforms,如何获取用户在WIndows 7和WIndows 8中使用的个人资料图片?(我主要想在Windows8上使用这个)。到目前为止,我只看到一堆论坛帖子说这是不可能做到的,但我看到应用程序可以做到这一点。根据: 这显示了如何设置用户磁贴(图片)。在接近尾声的评论中(迈克尔·安东尼,4月10日,22:45),评论者描述了如何获得图片。我已将信息收集到一个C#代码片段中。请记住,这是基于未记录的Windows Shell函数 using System; using System.Text

如何获取用户在WIndows 7和WIndows 8中使用的个人资料图片?(我主要想在Windows8上使用这个)。到目前为止,我只看到一堆论坛帖子说这是不可能做到的,但我看到应用程序可以做到这一点。

根据:

这显示了如何设置用户磁贴(图片)。在接近尾声的评论中(迈克尔·安东尼,4月10日,22:45),评论者描述了如何获得图片。我已将信息收集到一个C#代码片段中。请记住,这是基于未记录的Windows Shell函数

    using System;
    using System.Text;
    using System.Drawing;

    [DllImport("shell32.dll", EntryPoint = "#261", 
               CharSet = CharSet.Unicode, PreserveSig = false)]
    public static extern void GetUserTilePath(
      string username, 
      UInt32 whatever, // 0x80000000
      StringBuilder picpath, int maxLength);

    public static string GetUserTilePath(string username)
    {   // username: use null for current user
        var sb = new StringBuilder(1000);
        GetUserTilePath(username, 0x80000000, sb, sb.Capacity);
        return sb.ToString();
    }

    public static Image GetUserTile(string username)
    {
        return Image.FromFile(GetUserTilePath(username));
    }
请注意,此Shell函数创建文件\Users\\AppData…\.bmp并返回其文件名

另外,我已经在Win7上测试了它。我不知道它是否与以前的Windows版本兼容

贷记和。

根据:

这显示了如何设置用户磁贴(图片)。在接近尾声的评论中(迈克尔·安东尼,4月10日,22:45),评论者描述了如何获得图片。我已将信息收集到一个C#代码片段中。请记住,这是基于未记录的Windows Shell函数

    using System;
    using System.Text;
    using System.Drawing;

    [DllImport("shell32.dll", EntryPoint = "#261", 
               CharSet = CharSet.Unicode, PreserveSig = false)]
    public static extern void GetUserTilePath(
      string username, 
      UInt32 whatever, // 0x80000000
      StringBuilder picpath, int maxLength);

    public static string GetUserTilePath(string username)
    {   // username: use null for current user
        var sb = new StringBuilder(1000);
        GetUserTilePath(username, 0x80000000, sb, sb.Capacity);
        return sb.ToString();
    }

    public static Image GetUserTile(string username)
    {
        return Image.FromFile(GetUserTilePath(username));
    }
请注意,此Shell函数创建文件\Users\\AppData…\.bmp并返回其文件名

另外,我已经在Win7上测试了它。我不知道它是否与以前的Windows版本兼容


归功于和。

@jbabey-当然,这应该是一个答案,而不是一个评论。已经做了充分的研究,但没有发现任何适用于Windows 7及以下版本的内容。我不再使用Windows7(或Vista),因此我需要知道我找到的代码会起作用,而不是依赖那些声称这不是获得个人资料图片的保证方式的人所写的答案。谢谢你的链接;它没有出现在任何结果中。该链接仅用于应用商店应用程序,而不是winforms,也不是wpf。@jbabey-当然,这应该是一个答案,而不是一个注释。已经做了充分的研究,但没有找到适用于Windows 7及以下版本的任何内容。我不再使用Windows7(或Vista),因此我需要知道我找到的代码会起作用,而不是依赖那些声称这不是获得个人资料图片的保证方式的人所写的答案。谢谢你的链接;它没有出现在任何结果中。该链接仅用于商店应用程序,而不是winforms和wpf。非常感谢@One Man Crew!非常感谢:-)@One Man Crew非常有用!非常感谢“一人小组”!非常感谢:-)@One Man Crew非常有用!