It is currently Thu Jun 07, 2018 9:58 pm

All times are UTC - 8 hours [ DST ]


Forum rules


Before posting a bug report or a feature request, search the forum for an older post on the same topic. If you are reporting a crash, try capturing a crash dump. You can find instructions here: How to capture crash dumps



Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: User photo not loaded
PostPosted: Wed Sep 20, 2017 1:01 pm 
Offline

Joined: Wed Sep 20, 2017 12:48 pm
Posts: 3
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


Top
 Profile  
Reply with quote  
PostPosted: Thu Sep 21, 2017 4:25 am 
Offline
User avatar

Joined: Thu Jan 03, 2013 12:38 am
Posts: 5341
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

_________________
Links to some general topics:

Compare Start Menus

Read the Search box usage guide.

I am a Windows enthusiast and did Classic Shell's testing and usability/UX feedback.


Top
 Profile  
Reply with quote  
PostPosted: Thu Sep 21, 2017 6:16 am 
Offline

Joined: Wed Sep 20, 2017 12:48 pm
Posts: 3
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


Top
 Profile  
Reply with quote  
PostPosted: Thu Sep 21, 2017 7:49 am 
Offline
Site Admin
User avatar

Joined: Wed Jan 02, 2013 11:38 pm
Posts: 5331
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.


Top
 Profile  
Reply with quote  
PostPosted: Thu Sep 21, 2017 11:50 am 
Offline

Joined: Wed Sep 20, 2017 12:48 pm
Posts: 3
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


Top
 Profile  
Reply with quote  
PostPosted: Fri Sep 22, 2017 8:17 am 
Offline
Site Admin
User avatar

Joined: Wed Jan 02, 2013 11:38 pm
Posts: 5331
Classic Shell uses the undocumented interface IUserTileStore to get the path to the user image.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group, Almsamim WYSIWYG Classic Shell © 2010-2016, Ivo Beltchev.
All right reserved.