How to set the Windows 7 user account picture programmatically?

Posted by on Aug 12, 2011 in C#, Environment, | 6 comments

Windows 7 offers the possibility to show small user account pictures, for example in the start menu or on the lock screen. Since there is no documented way of setting this picture programmatically here is a solution for developing a small application that can do this for you.
You’ll simply need Visual Studio – either with C# or Visual Basic support. You can get your free edition here: Create a new console application, copy and paste the following source code an build the solution. The resulting application will be able to set the user account pictures for you.

C# source:

using System;
using System.Runtime.InteropServices;

namespace useraccountpicture
    class Program
        [DllImport("shell32.dll", EntryPoint = "#262", CharSet = CharSet.Unicode, PreserveSig = false)]
        public static extern void SetUserTile(string username, int notneeded, string picturefilename);

        static void Main(string[] args)
            if (args.Length == 2)
                SetUserTile(args[0], 0, args[1]);

Visual Basic source:

Imports System.Runtime.InteropServices

Module useraccountpicture

    <DllImport("shell32.dll", EntryPoint:="#262", CharSet:=CharSet.Unicode, PreserveSig:=False)> _
    Private Sub SetUserTile(ByVal username As String, ByVal notneeded As Integer, ByVal picturefilename As String)
    End Sub

    Sub Main(ByVal args As String())
        If (args.Length = 2) Then
            SetUserTile(args(0), 0, args(1))
        End If
    End Sub

End Module

Now run it on a command line, for example:
useraccountpicture.exe domain\username picturefilename.jpg

Please note that this will not affect the logon screen. Since windows cannot know which user will logon it cannot display a picture.


  1. Thank you so much!
    I had been looking for a way to do this for so long and had nearly given up hope on it. Very, very helpful.

  2. simple if you know how to do it, but insanely difficult if you do not know where to start looking.

    Thanks so much!

  3. Thanks for this. Not only did it work perfectly, but I was also able to learn a little about Visual Studio so thanks for that too!

  4. You’re welcome!

  5. does this update the user account in active directory, or just the local machine instance?

  6. No, it does not update any information on active directory. You can refer to on how to update pictures in ad.

Leave a Reply

Your email address will not be published. Required fields are marked *

Captcha: * Time limit is exhausted. Please reload CAPTCHA.