You are viewing our Forum Archives. To view or take place in current topics click here.
How to get Windows User Account Picture? [VB.NET]
Posted:

How to get Windows User Account Picture? [VB.NET]Posted:

PoisonOak
  • Resident Elite
Status: Offline
Joined: Mar 29, 201212Year Member
Posts: 248
Reputation Power: 11
Status: Offline
Joined: Mar 29, 201212Year Member
Posts: 248
Reputation Power: 11
I'm working on a project and i've been looking around for either a directory to the user's account .bmp file or a registry key with the location of it but i can't find it.

And yes i've looked online and i can't seem to find any help there. Has anyone ever done this before and can give me a way to retrieve the user's picture? This should be able to get it from 7, 8, and 8.1 if possible, thanks.
#2. Posted:
AAW
  • TTG Senior
Status: Offline
Joined: Apr 30, 201113Year Member
Posts: 1,574
Reputation Power: 70
Status: Offline
Joined: Apr 30, 201113Year Member
Posts: 1,574
Reputation Power: 70
Windows 8.1 Location
C:\Users\{username}\AppData\Roaming\Microsoft\Windows\AccountPictures\{FileName}
#3. Posted:
Odin
  • Christmas!
Status: Offline
Joined: Dec 23, 201013Year Member
Posts: 2,446
Reputation Power: 80
Status: Offline
Joined: Dec 23, 201013Year Member
Posts: 2,446
Reputation Power: 80
Why don't you just screenshot the picture and with a bit of microsoft paint magic you'll have the image..
#4. Posted:
TGK
  • TTG Senior
Status: Offline
Joined: Oct 03, 201311Year Member
Posts: 1,409
Reputation Power: 64
Status: Offline
Joined: Oct 03, 201311Year Member
Posts: 1,409
Reputation Power: 64
Even wrote Why don't you just screenshot the picture and with a bit of microsoft paint magic you'll have the image..

Because what if multiple people use his program? He wouldn't be able to do that...
Think a little.
#5. Posted:
Imp
  • Blind Luck
Status: Offline
Joined: Jan 01, 201113Year Member
Posts: 1,957
Reputation Power: 401
Status: Offline
Joined: Jan 01, 201113Year Member
Posts: 1,957
Reputation Power: 401
For Windows 7 this is the best way I have found

Imports required


Imports System
Imports System.Text
Imports System.Drawing
Imports System.Runtime.InteropServices


Put this code inside your Forms Class


    <DllImport("shell32", EntryPoint:="#261", CharSet:=CharSet.Unicode, PreserveSig:=False)> _
    Public Shared Sub GetUserTilePath(username As String, whatever As UInt32, picpath As StringBuilder, maxLength As Integer)
    End Sub

    Public Function GetUserTilePath(username As String) As String
        Dim sb As StringBuilder
        sb = New StringBuilder(1000)
        GetUserTilePath(username, 2147483648, sb, sb.Capacity)
        Return sb.ToString()
    End Function

    Public Function GetUserTile(username As String) As Image
        Return Image.FromFile(GetUserTilePath(username))
    End Function


Then call it when assigning an image to a picturebox like this



GetUserTile(System.Security.Principal.WindowsIdentity.GetCurrent().Name)



This will put the current users Picture in the picture box ;)
#6. Posted:
PoisonOak
  • Resident Elite
Status: Offline
Joined: Mar 29, 201212Year Member
Posts: 248
Reputation Power: 11
Status: Offline
Joined: Mar 29, 201212Year Member
Posts: 248
Reputation Power: 11
Imp wrote For Windows 7 this is the best way I have found

Imports required


Imports System
Imports System.Text
Imports System.Drawing
Imports System.Runtime.InteropServices


Put this code inside your Forms Class


    <DllImport("shell32", EntryPoint:="#261", CharSet:=CharSet.Unicode, PreserveSig:=False)> _
    Public Shared Sub GetUserTilePath(username As String, whatever As UInt32, picpath As StringBuilder, maxLength As Integer)
    End Sub

    Public Function GetUserTilePath(username As String) As String
        Dim sb As StringBuilder
        sb = New StringBuilder(1000)
        GetUserTilePath(username, 2147483648, sb, sb.Capacity)
        Return sb.ToString()
    End Function

    Public Function GetUserTile(username As String) As Image
        Return Image.FromFile(GetUserTilePath(username))
    End Function


Then call it when assigning an image to a picturebox like this



GetUserTile(System.Security.Principal.WindowsIdentity.GetCurrent().Name)



This will put the current users Picture in the picture box ;)


Works like a charm, never understood dll inputs, thanks a lot
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.