Created
May 27, 2023 23:44
-
-
Save puppis42/d74ffcc2335e018a89768ee8f8eaffaa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.InteropServices; | |
using System.Text; | |
using System.Drawing; | |
using System.Drawing.Imaging; | |
using System.Linq; | |
namespace GetAccountProfilePicture | |
{ | |
class Program | |
{ | |
[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)); | |
} | |
static void Main(string[] args) | |
{ | |
string uname = System.Security.Principal.WindowsIdentity.GetCurrent().Name.Split('\\').Last(); | |
Image img = GetUserTile(uname); | |
img.Save(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)+"\\pic.png", ImageFormat.Png); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment