更改所有用户的墙纸

Changing ALL user's wallpaper

最近我遇到了一种情况,我们需要使用 PowerShell 设置默认壁纸以及任何现有用户的壁纸。

我们可以通过替换文件 C:\Windows\Web\Wallpaper\Windows\img0.jpg 来设置默认壁纸,但我还没有找到合适的解决方案来替换任何现有的壁纸。

我考虑过/尝试过的一些事情:

我是不是完全漏掉了什么?有人对我们如何设置它有建议吗?

提前致谢!

经过一番尝试,这就是我的想法。我不是 PowerShell 专家,所以请随意提出一些更好的解决方案。

# Get each folder under "Users"
$drive = (Get-Location).Drive.Root
$users = Get-ChildItem "$($drive)Users"

# For each user, load and edit their registry
foreach ( $user in $users ) {

    # If this isn't us, load their hive and set the directory
    # If this is us, use HKEY_CURRENT_USER
    if ( $user.Name -ne $env:username ) {
        reg.exe LOAD HKU\Temp "$($drive)Users$($user.Name)\NTUSER.DAT"
        $dir = "Registry::HKEY_USERS\Temp\Control Panel\Desktop"
    } else {
        $dir = "Registry::HKEY_CURRENT_USER\Control Panel\Desktop"
    }

    # We don't care about users that don't have this directory
    if ( (Test-Path $dir) ) {

        # Set the image
        Set-ItemProperty -Path $dir -Name "Wallpaper" -value "$($drive)Users\Public\Pictures\Sample Pictures\Tulips.jpg"

        # Set the style to stretch
        Set-ItemProperty -Path $dir -Name "WallpaperStyle" -value 2

    }

    # Unload user's hive
    if ( $user.Name -ne $env:username ) {
        [gc]::Collect()
        reg.exe UNLOAD HKU\Temp
    }
}

感谢 TheMadTechnician 的 GPO 建议。一般情况下,我肯定同意!