C # Get user image (Avatar)

I mean C # - How to get the current user image , but I did not find a solution. (I am working on Win7 OS)

For some users, the image is on

C: \ Users \ username \ AppData \ Local \ Temp \ UserName.bmp

(where UserName is the nickname of the user) for other users, this path throws a FileNotFoundException, but images exist.

Where can I find information about the path or the real picture? Is there a registry that contains this information?

+5
source share
2 answers

, (). ( , 10 , 22:45), , . #. , 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\<USER> \AppData...\<USER> .bmp .

, Win7. Windows.

Joco .

+9

\HKEY_CURRENT_USER\Volatile Envirnment, .

, C:\Users\UserName\AppData\Local\Temp\, :

// Note that $XYZ$ means \HKEY_CURRENT_USER\Volatile Envirnment\XYZ
if $USERDOMAIN$ = "" then
    return $USERNAME$.Substring(0, $USERNAME$.IndexOf('.'));
else
    return $USERDOMAIN$ + "+" + $USERNAME$.Substring(0, $USERNAME$.IndexOf('.'));

, .

P.S.: Volatile Environment, \HKEY_USERS. , Volatile Environment (- \HKEY_USERS , ).

0

All Articles