【问题标题】:Changing ALL user's wallpaper更改所有用户的壁纸
【发布时间】:2016-08-18 03:51:12
【问题描述】:

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

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

我曾想过/尝试过的一些事情:

  • 从注册表设置壁纸。这样做的问题是针对每个用户。
  • 删除和复制 TranscodedWallpaper 文件。问题在于 Windows 7 将文件命名为 TranscodedWallpaper.jpg,Windows 8 将其命名为 TranscodedWallpaper.bmp,而 Windows 10 只是 TranscodedWallpaper。虽然我想我们可以创建三个不同版本的文件并检查操作系统版本,但我更愿意在采取这条路线之前确认没有其他解决方案。

我在这里完全错过了什么吗?有人对我们如何设置有任何建议吗?

提前致谢!

【问题讨论】:

  • 使用 GPO 怎么样?组策略做了很多巧妙的事情。
  • 完全同意,但我们并不总是知道这些计算机是否会安装 GPO。我现在正在研究的是加载用户配置单元。看起来很有希望。
  • “使用 GPO 设置”是什么意思?只需将计算机对象放入 AD 中的相应 OU 中,GPO 就会自动应用。
  • @Bill_Stewart 请原谅我的措辞,其中一些计算机是家用计算机,没有设置 Active Directory。
  • 所以任务是管理非托管机器。如果要管理它们,请将它们加入域并应用 GPO。 (如果它们不受管理,则它们不受管理。)

标签: windows powershell powershell-2.0


【解决方案1】:

在玩了一些之后,这就是我想出的。我不是 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 建议。一般情况下,我肯定会同意的!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-04
    • 1970-01-01
    • 2011-05-02
    • 2016-12-11
    • 1970-01-01
    • 2014-05-28
    相关资源
    最近更新 更多