Question

I need to extract user pictures out of Active Directory (LDS) and save them as a .jpeg file. I am able to extract the binary 64 data for the photo attribute in AD but I don't know how to write it to a usable .jpeg file in my .vbs script. Please post sample code!

Was it helpful?

Solution

Since you already have the extracted binary data.. here's a sub to take that data and create a .jpg file. Just pass the binary data and a path to save (ie. c:\temp\pic.jpg).

Sub writeImage(binaryData, strFullPath)

  Set objADO = CreateObject("ADODB.Stream")
  objADO.Open
  objADO.Type = 1
  objADO.Position = 0

  objADO.Write binaryData
  objADO.SaveToFile strFullPath

  Set objADO = Nothing

End Sub

If you didn't have the data, you could use this to pull it from a URL.

Function binaryURL(strURL)
  Set objHttp = CreateObject("WinHttp.WinHttpRequest.5.1")

  objHTTP.Open "GET", strURL, False
  objHTTP.Send

  binaryURL = objHTTP.ResponseBody
End Function

And then just do a..

Call writeImage(binaryURL("http://i.imgur.com/fr16Y6W.jpg"), "C:\temp\pic.jpg")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top