Classic Shell
http://www.classicshell.net/forum/

User photo not loaded
http://www.classicshell.net/forum/viewtopic.php?f=12&t=7921
Page 1 of 1

Author:  skonvols2k [ Wed Sep 20, 2017 1:01 pm ]
Post subject:  User photo not loaded

Hi,
as many users do i have my company's users photos loaded in active directory, Windows 10 users' photos are loaded by the powershell logon below:
Code:
[CmdletBinding(SupportsShouldProcess=$true)]Param()
function Test-Null($InputObject) { return !([bool]$InputObject) }

Function ResizeImage() {
param([String]$ImagePath, [Int]$Quality = 90, [Int]$targetSize, [String]$OutputLocation)

Add-Type -AssemblyName "System.Drawing"

$img = [System.Drawing.Image]::FromFile($ImagePath)

$CanvasWidth = $targetSize
$CanvasHeight = $targetSize

#Encoder parameter for image quality
$ImageEncoder = [System.Drawing.Imaging.Encoder]::Quality
$encoderParams = New-Object System.Drawing.Imaging.EncoderParameters(1)
$encoderParams.Param[0] = New-Object System.Drawing.Imaging.EncoderParameter($ImageEncoder, $Quality)

# get codec
$Codec = [System.Drawing.Imaging.ImageCodecInfo]::GetImageEncoders() | Where {$_.MimeType -eq 'image/jpeg'}

#compute the final ratio to use
$ratioX = $CanvasWidth / $img.Width;
$ratioY = $CanvasHeight / $img.Height;

$ratio = $ratioY
if ($ratioX -le $ratioY) {
$ratio = $ratioX
}

$newWidth = [int] ($img.Width * $ratio)
$newHeight = [int] ($img.Height * $ratio)

$bmpResized = New-Object System.Drawing.Bitmap($newWidth, $newHeight)
$graph = [System.Drawing.Graphics]::FromImage($bmpResized)
$graph.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic

$graph.Clear([System.Drawing.Color]::White)
$graph.DrawImage($img, 0, 0, $newWidth, $newHeight)

#save to file
$bmpResized.Save($OutputLocation, $Codec, $($encoderParams))
$bmpResized.Dispose()
$img.Dispose()
}

#get sid and photo for current user
$user = ([ADSISearcher]"(&(objectCategory=User)(SAMAccountName=$env:username))").FindOne().Properties
$user_photo = $user.thumbnailphoto
$user_sid = [System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value
Write-Verbose "Updating account picture for $($user.displayname)..."

#continue if an image was returned
If ((Test-Null $user_photo) -eq $false)
{
Write-Verbose "Success. Photo exists in Active Directory."

#set up image sizes and base path
$image_sizes = @(32, 40, 48, 96, 192, 200, 240, 448)
$image_mask = "Image{0}.jpg"
$image_base = $env:public + "\AccountPictures"

#set up registry
$reg_base = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AccountPicture\Users\{0}"
$reg_key = [string]::format($reg_base, $user_sid)
$reg_value_mask = "Image{0}"
If ((Test-Path -Path $reg_key) -eq $false) { New-Item -Path $reg_key }

#save images, set reg keys
ForEach ($size in $image_sizes)
{
#create hidden directory, if it doesn't exist
$dir = $image_base + "\" + $user_sid
If ((Test-Path -Path $dir) -eq $false) { $(mkdir $dir).Attributes = "Hidden" }

#save photo to disk, overwrite existing files
$file_name = ([string]::format($image_mask, $size))
$pathtmp = $dir + "\_" + $file_name
$path = $dir + "\" + $file_name
Write-Verbose " saving: $file_name"
$user_photo | Set-Content -Path $pathtmp -Encoding Byte -Force
ResizeImage $pathtmp $size $size $path
Remove-Item $pathtmp

#save the path in registry, overwrite existing entries
$name = [string]::format($reg_value_mask, $size)
$value = New-ItemProperty -Path $reg_key -Name $name -Value $path -Force
}

Write-Verbose "Done."
} else { Write-Error "No photo found in Active Directory for $env:username" }


The script basicly write a file for each resolution in C:\Users\Public\AccountPictures and creates the appropiate records in registry in HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AccountPicture\Users

With this method user's photo is correctly show at login and in all other places, except for in classicshell menu, it show the anonimusgray photo

it's possibile to fix that?

Thanks

Author:  Gaurav [ Thu Sep 21, 2017 4:25 am ]
Post subject:  Re: User photo not loaded

Try using Classic Start Menu's own "User picture" setting? It's on the General Behavior tab and its reg value is: HKCU\Software\IvoSoft\ClassicStartMenu\Settings. String value: UserPicturePath. A single high-res pic should work.

If you change the Classic Start Menu Registry key, make sure to exit the Start Menu first and then start it again:
C:\Program Files\Classic Shell\ClassicStartMenu.exe -exit
C:\Program Files\Classic Shell\ClassicStartMenu.exe

Author:  skonvols2k [ Thu Sep 21, 2017 6:16 am ]
Post subject:  Re: User photo not loaded

Gaurav wrote:
Try using Classic Start Menu's own "User picture" setting? It's on the General Behavior tab and its reg value is: HKCU\Software\IvoSoft\ClassicStartMenu\Settings. String value: UserPicturePath. A single high-res pic should work.


The strange think is that if you manually change user picture in windows settings, classic shell will automatically load it, but setting the user picture in windows via the provided script classicshell doesn't load that.
I will prefer that classicshell will load windows user picture automatically without setting the reg value you provide.
Thanks

Author:  Ivo [ Thu Sep 21, 2017 7:49 am ]
Post subject:  Re: User photo not loaded

Classic Shell simply asks Windows what bitmap to use.
You need to figure out what is the difference between manually setting the picture and running your script. Possibly you can run Process Monitor and see what is written where.

Author:  skonvols2k [ Thu Sep 21, 2017 11:50 am ]
Post subject:  Re: User photo not loaded

Ivo wrote:
Classic Shell simply asks Windows what bitmap to use.
You need to figure out what is the difference between manually setting the picture and running your script. Possibly you can run Process Monitor and see what is written where.


Hi,
i certainly do that, can you help me explaining how Classic Shell asks to windows what bitmap to use? Is a file? a Reg value?
i'm a sysadmin so don't worry and be specific :D
Thanks

Author:  Ivo [ Fri Sep 22, 2017 8:17 am ]
Post subject:  Re: User photo not loaded

Classic Shell uses the undocumented interface IUserTileStore to get the path to the user image.

Page 1 of 1 All times are UTC - 8 hours [ DST ]
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/