This topic is little more complex and we’ll need different steps to accomplish this feature.
First at all you need the pictures for your user objects in the directory. You can use ADSI Edit, Powershell or 3rd party software to put pictures in AD. My blog post “How to save a user picture in Active Directory with vbScript?” will do this for you using vbScript.
Second you’ll need a small application that sets a picture on your harddrive as the user account picture. I tested this only with Windows 7 – so there is no guarantee that this works with other versions too. Why an application? Because there is no documented way of setting an individual user account picture programmatically in vbScript – neither via registry nor via file system.
My blog post “How to set the Windows 7 user account picture programmatically?” covers that small application.
Now that we have the pictures in Active Directory and developed a small application that sets an image file as user account picture we just need one more step between both. We need a vbScript that runs at logon, loads the picture from AD, puts it on the disk and calls our application. Here we go:
Function LoadPictureFromAD(szADsPath, szSaveFileName) Dim objUser, bytesRead, adoStreamWrite Const adTypeBinary = 1, adSaveCreateOverWrite = 2 Set objUser = GetObject(szADsPath) bytesRead = objUser.Get("thumbnailPhoto") Set adoStreamWrite = CreateObject("ADODB.Stream") adoStreamWrite.Type = adTypeBinary adoStreamWrite.Open adoStreamWrite.Write(bytesRead) adoStreamWrite.SaveToFile szSaveFileName, adSaveCreateOverWrite adoStreamWrite.Close End Function Set wshShell = CreateObject("WScript.Shell") Set fso = CreateObject("Scripting.FileSystemObject") workingdir = Replace(wscript.scriptfullname, Wscript.scriptname, "") Set wshNetwork = WScript.CreateObject("WScript.Network") username = wshNetwork.UserDomain & "\" & wshNetwork.UserName Set objSysInfo = CreateObject("ADSystemInfo") strUserName = objSysInfo.UserName dn = "LDAP://" & strUserName path = wshShell.ExpandEnvironmentStrings("%temp%") & "\" filename = path & "uap.jpg" LoadPictureFromAD dn, filename wshshell.run workingdir & "useraccountpicture.exe " & username & " " & filename, 0, true
This script contains the function LoadPictureFromAD which expects the user’s distinguished name and a filename where the resulting picture will be saved to. Inside the function we connect to AD, get the user’s object, read the attribute thumbnailPhoto, copy it to a previously created stream object and save it in a file identified by szSaveFileName.
The script itself assumes that the useraccountpicture.exe application resists in the same location as the script. So we set the working directory to the scripts location. After that we need the user’s name, it’s domain and it’s distinguished name. Then we create the filename for the image, this is simply the temp folder with “uap.jpg” as filename. With the distinguished name and the filename we can call the LoadPictureFromAD function and finally we run the useraccountpicture application with the username and the filename as parameters.
Save the script as .vbs – run it – have a look at the start menu – that’s all…
Now you can use this script as a logon script within group policies and all your users can find their photos in the start menu and on the lock screen.