You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Windows 10 PowerShell获取当前锁屏壁纸方法求助

Got it, let's tackle this. You need to grab the user's existing lock screen wallpaper before swapping it out for your custom one during workstation updates—then restore it once everything's done. Here's a reliable PowerShell approach that covers all common scenarios on Windows 10/11:

Step 1: Capture the Current Lock Screen Wallpaper Settings

Windows stores lock screen configurations in two main places: user-specific custom wallpapers and system/OEM-deployed backgrounds. We'll check both to ensure we don't miss anything.

For User-Defined Lock Screens

If the user set their own lock screen via Settings > Personalization > Lock screen, the path is stored in their user registry:

# Fetch the user's custom lock screen path (if it exists)
$userLockScreenPath = Get-ItemPropertyValue -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Lock Screen" -Name "ImagePath" -ErrorAction SilentlyContinue

For System/OEM Lock Screens

In enterprise environments, lock screens are often set via group policy or OEM tools. Check the system registry for these settings:

# Verify if a system/OEM background is enabled
$oemBackgroundEnabled = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background" -Name "OEMBackground" -ErrorAction SilentlyContinue
$systemLockScreenPath = $null

if ($oemBackgroundEnabled -eq 1) {
    $systemLockScreenPath = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background" -Name "BackgroundImagePath" -ErrorAction SilentlyContinue
}

Save Settings for Later Restoration

Store the captured data in a temporary JSON file (it persists through the update process even if the session restarts):

$tempBackupFile = "$env:TEMP\LockScreenBackup.json"
$backupConfig = [PSCustomObject]@{
    UserImagePath = $userLockScreenPath
    SystemImagePath = $systemLockScreenPath
    OEMBackgroundEnabled = $oemBackgroundEnabled
} | ConvertTo-Json

$backupConfig | Out-File -FilePath $tempBackupFile -Encoding UTF8

Step 2: Restore the Original Lock Screen After Updates

Once your update workflow completes, retrieve the backup and revert the lock screen to its original state:

# Load the saved backup configuration
$backupConfig = Get-Content -Path $tempBackupFile -Raw | ConvertFrom-Json

# Restore user-specific lock screen
if ($backupConfig.UserImagePath) {
    Set-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Lock Screen" -Name "ImagePath" -Value $backupConfig.UserImagePath
} else {
    # If no custom user wallpaper existed, reset to default/Spotlight
    Remove-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Lock Screen" -Name "ImagePath" -ErrorAction SilentlyContinue
}

# Restore system/OEM lock screen (if applicable)
if ($backupConfig.OEMBackgroundEnabled -eq 1 -and $backupConfig.SystemImagePath) {
    Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background" -Name "BackgroundImagePath" -Value $backupConfig.SystemImagePath
}

# Force Windows to refresh lock screen settings immediately
rundll32.exe user32.dll,UpdatePerUserSystemParameters 1, True

# Clean up the temporary backup file
Remove-Item -Path $tempBackupFile -ErrorAction SilentlyContinue

Important Notes

  • Admin Rights: Modifying system registry keys (HKLM) requires running PowerShell as an administrator. Ensure your update script elevates itself if needed.
  • Spotlight/Default Wallpapers: If the user was using Windows Spotlight or the default system wallpaper, the ImagePath registry key won't exist. Our script handles this by removing the key (if present) to revert to default behavior.
  • Lock Screen Refresh: The rundll32 command forces Windows to apply restored settings right away, so users won't see your custom wallpaper after the update finishes.

内容的提问来源于stack exchange,提问作者KHaemels

火山引擎 最新活动