Skip to content

Instantly share code, notes, and snippets.

@norman-bauer
Last active April 13, 2018 07:20
Show Gist options
  • Save norman-bauer/8bd02b0c886da5cf23a76a363fac8fee to your computer and use it in GitHub Desktop.
Save norman-bauer/8bd02b0c886da5cf23a76a363fac8fee to your computer and use it in GitHub Desktop.
How to display Active Directory stored user account pictures in Windows?
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
'Find useraccountpicture.exe's code at https://www.normanbauer.com/2011/08/12/how-to-set-the-windows-7-user-account-picture-programmatically/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment