Skip to content

Commit

Permalink
feat(PFP): rewrite in PowerShell
Browse files Browse the repository at this point in the history
  • Loading branch information
he3als committed Oct 19, 2023
1 parent 3869332 commit 9e6cc16
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 33 deletions.
5 changes: 3 additions & 2 deletions src/playbook/Configuration/tweaks/scripts/script-pfp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ description: Sets the default Atlas profile pictures
privilege: TrustedInstaller
actions:
- !run:
exe: 'powershell.exe'
args: '-NoP -File "PFP.ps1"'
wait: true
exeDir: true
exe: 'PFP.cmd'
weight: 20
31 changes: 0 additions & 31 deletions src/playbook/Executables/PFP.cmd

This file was deleted.

53 changes: 53 additions & 0 deletions src/playbook/Executables/PFP.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
Add-Type -AssemblyName System.Drawing
$img = [System.Drawing.Image]::FromFile((Get-Item '.\user.png'))

$perUserResolutions = @(1080, 448, 424, 240, 208, 192, 96, 64, 48, 40, 32)
$resolutions = @{
"user.png" = 448
"user.bmp" = 448
"guest.png" = 448
"guest.bmp" = 448
"user-192.png" = 192
"user-48.png" = 48
"user-40.png" = 40
"user-32.png" = 32
}

# Set default profile pictures
foreach ($image in $resolutions.Keys) {
$resolution = $resolutions[$image]

$a = New-Object System.Drawing.Bitmap($resolution, $resolution)
$graph = [System.Drawing.Graphics]::FromImage($a)
$graph.DrawImage($img, 0, 0, $resolution, $resolution)
$a.Save("$env:ProgramData\Microsoft\User Account Pictures\$image")
}

# Set Atlas profile picture for each user
function SetUserProfileImage($sid) {
$usrPfpDir = "$env:public\AccountPictures\$sid"

if (!(Test-Path $usrPfpDir)) {
# New-Item -Path $usrPfpDir -ItemType Directory -Force | Out-Null
# This doesn't overwrite users that have manually set profile pictures
return
}

foreach ($resolution in $perUserResolutions) {
$a = New-Object System.Drawing.Bitmap($resolution, $resolution)
$graph = [System.Drawing.Graphics]::FromImage($a)
$graph.DrawImage($img, 0, 0, $resolution, $resolution)
$a.Save("$usrPfpDir\$resolution`x$resolution.png")

New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AccountPicture\Users\$sid" -Name "Image$resolution" `
-PropertyType String -Value "$usrPfpDir\$resolution`x$resolution.png" -Force | Out-Null
}
}

# Recurse through user keys and set profile pictures
foreach ($userKey in $((Get-ChildItem -Path "Registry::HKEY_USERS").Name | Where-Object { $_ -like 'HKEY_USERS\S-*' })) {
Get-ItemProperty -Path "Registry::$userKey\Volatile Environment" -ErrorAction SilentlyContinue | Out-Null
if ($?) {
SetUserProfileImage "$($userKey -replace 'HKEY_USERS\\','')"
}
}

0 comments on commit 9e6cc16

Please sign in to comment.