New folder/usertile1.png
New folder/usertile10.png
New folder/usertile11.png
New folder/usertile12.png
New folder/usertile13.png
New folder/usertile14.png
New folder/usertile15.png
New folder/usertile16.png
New folder/usertile17.png
New folder/usertile18.png
New folder/usertile19.png
New folder/usertile20.png
New folder/usertile21.png
New folder/usertile22.png
New folder/usertile23.png
New folder/usertile24.png
New folder/usertile25.png
New folder/usertile26.png
New folder/usertile27.png
New folder/usertile28.png
New folder/usertile29.png
New folder/usertile30.png
New folder/usertile31.png
New folder/usertile32.png
New folder/usertile33.png
New folder/usertile34.png
New folder/usertile35.png
New folder/usertile36.png
New folder/usertile37.png
New folder/usertile38.png
New folder/usertile39.png
New folder/usertile40.png
New folder/usertile41.png
New folder/usertile42.png
New folder/usertile43.png
New folder/usertile44.png
I’ve blogged in the past about adding Thumbnails to Active Directory but I could not believe that I hadn’t thought about how these do not translate into the login tile in Windows 7 and Server 2008 R2. Surely it’s just logical for this to be easy.
I looked around the Internet and found source code for you to create your own .exe file and many complicated answers, but with a little help I’ve got the basics down to a very simple script indeed.
Yes, PowerShell again. User Tiles are a 6.1 feature and installation of PowerShell as standard is a 6.1 feature. For those of you who interested and don’t know, Windows 7 and Windows Server 2008 R2 are “version 6.1”. I think I called it “Longhorn, fixed” when it first came out.
This little script takes a username, which has already been used to log onto the local PC, and an image file. The undocumented function at ordinal 262 does all of the hard work. It resizes the image and does the magic.
As I’ve worked on it, I’ve found variations around the internet of the bits I’ve done so far. Such as this which helped me with the Single Threaded Appartment issue.
# This script msut be run in STA mode to avoid casting errors
# powershell.exe -STA
param ( [string] $User, [string] $ImagePath )
# Create the call to the User Tile API
[string] $SourceCode = @”
[DllImport(“shell32.dll”, EntryPoint = “#262”, CharSet = CharSet.Unicode, PreserveSig = false)]
public static extern void SetUserTile(string username, int whatever, string picpath);
“@
$type = Add-Type -Namespace iammarkharrison -Name Tiles -MemberDefinition $SourceCode -PassThru
#Set the User Tile
[iammarkharrison.Tiles]::SetTile($User,$ImagePath)
That’s a good start and it’s certainly the shortest script that does this job that I’ve seen, but having blogged on how to upload thumbnailPhoto in Active Directory, I want to download the thumbnail from AD and use that.
More to follow on that subject. Well, there would have been if someone else had not done it already. It’s really simple to convert the above script.
# Create the call to the User Tile API
[string] $SourceCode = @"
[DllImport("shell32.dll", EntryPoint = "#262", CharSet = CharSet.Unicode, PreserveSig = false)]
public static extern void SetUserTile(string username, int whatever, string picpath);
"@
$type = Add-Type -Namespace iammarkharrison -Name Tiles -MemberDefinition $SourceCode -PassThru
if ($host.Runspace.ApartmentState -ne “STA”) {
# Relaunch if not in STA mode
powershell.exe -noprofile -sta “$($myInvocation.MyCommand.Path)”
}
else {
#Set the User Tile
$photo = ([ADSISEARCHER]”samaccountname=$($env:username)”).findone().properties.thumbnailphoto
$photo | set-content “$($env:temp)\$($env:userdomain)$($env:username).jpg” -Encoding byte
[iammarkharrison.Tiles]::SetUserTile(“$($env:userdomain)\$($env:username)”,0,”$($env:temp)\$($env:userdomain)$($env
:username).jpg”)
Exit
}
This should now be runnable in a logon script. The one thing I want to address is how small the thumbnails are in AD.
How to display User Picture Tile in Windows 7 Taskbar (Windows 8 feature)
As you probably already know, the design Windows 8 differs very little (for now) from Windows 7. Among the few differences listed in this article we mention…
Continuation
The Explanation
Back in 2010 as Microsoft was putting the finishing touches on Office 2010, the Microsoft Exchange team mentioned that it was going to possible to show pictures in Outlook 2010. They also talked about how these pictures could be loaded directly into Active Directory and Outlook would be able to pull them from the directory. It didn’t take me long to make the required schema change on our network at work and load a few pictures in for testing. Once I updated our system to support Windows 2008 domain controllers, the display of pictures in the beta version of Outlook started working perfectly.
Even before I got the picture display to work in Outlook, I started wondering if it would be possible to make Windows 7 automatically load those pictures for its User Tile (I actually even asked the question on the blog post by the MS Exchange Team). It seemed that this wasn’t possible. Supposedly the fact that this was desired was passed on to the Windows team, but even after Windows 7 SP1 came out there didn’t seem to be any official support for this feature. And as far as I can tell, none is forthcoming.
The other day, I happened across a post by a guy named Joco where he detailed an undocumented API in Windows 7 that sets the User Tile. He also included some sample C# code that you can execute with command line arguments for the username and the picture location. However, I want to load the pictures directly from AD and I’ve done most of my “programming” in Visual Basic, not C#. So, I took his sample code, translated the API declaration to VB and added some code to retrieve the picture from Active Directory.
The Executable File
For simplicity, I’m providing an executable file already compiled against .Net 3.5 (which comes with Windows 7). This executable is signed by a CA Cert code signing certificate. If you do not have their root certificates installed, Windows will tell you that it’s an invalid signature.
- setUserTile.exe
To use this file, it can be simply be run by the user. You can launch this automatically as part of a login script (which is how I use it). The logic script application I use also allows me to hide any output so the DOS box never gets seen by our users.
Note: The icon used in this executable is licensed under the CC Attribution-Noncommercial-Share Alike 3.0 license. I’m open to using a different icon if I can find one a little more representative of what the program is doing.
Source code and some basic directions for using it can be found after the break.
The VB.net Code
This code was written using the free Visual Basic 2010 Express. Once you have that installed, you can create a new Console Application named “setUserTile”.
From the “Project” menu, select “Add Reference…”
And add a reference to both “System.DirectoryServices” and “System.DirectoryServices.AccountManagement”.
NOTE: You may also wish to change the version of .Net for this application to 3.5, which is the version that ships with Windows 7. If you leave it at 4.0 (the default for VB.Net 2010) the application will only be able to run on systems that have installed v4.0 of the .Net framework.
Module setUserTile ' Undocumented API learned from http://joco.name/2010/12/06/i-discovered-the-new-windows-user-tile-api/ <system .Runtime.InteropServices.DllImport("shell32.dll", EntryPoint:="#262", CharSet:=Runtime.InteropServices.CharSet.Unicode, PreserveSig:=False)> _ Private Sub SetUserTile(ByVal strUserName As String, ByVal intWhatever As Integer, ByVal strPicPath As String) ' This is just to fool WordPress which thinks it's being helpful </system> End Sub Sub Main() Dim strUser As String Dim currentADUser As System.DirectoryServices.AccountManagement.UserPrincipal Dim de As System.DirectoryServices.DirectoryEntry Dim b() As Byte Dim strTempFile As String Dim stream As System.IO.FileStream Try ' The WindowsIdenty object can retrieve the current username (with domain), but not the AD Object ' The "AccountManagement" object can retrieve the current user, but not the thumbnailPhoto ' The "DirectoryEntry" object can retrieve the thumbnailPhoto, but not the current user ' So we use all three objects... ' The WindowsIdentity object to pass the full domain\username string to our API ' And the "AccountManagement" object to tell the "DirectoryEntry" object which user to get the photo for strUser = System.Security.Principal.WindowsIdentity.GetCurrent().Name currentADUser = System.DirectoryServices.AccountManagement.UserPrincipal.Current de = New System.DirectoryServices.DirectoryEntry("LDAP://" + currentADUser.DistinguishedName) b = de.Properties("thumbnailPhoto").Value If b IsNot Nothing Then ' We've got a picture... save it to %TEMP% ... strTempFile = System.IO.Path.GetTempFileName stream = New System.IO.FileStream(strTempFile, System.IO.FileMode.Create) stream.Write(b, 0, b.Length) stream.Close() ' ... call our API ... SetUserTile(strUser, 0, strTempFile) ' ... and delete the temporary file. System.IO.File.Delete(strTempFile) End If Catch ex As Exception ' Fail silently End Try End Sub End Module
setUserTile in VB.Net by Jacob Steenhagen is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Based on a work at joco.name.
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Sign up
Appearance settings
