更改所有用户的墙纸
Changing ALL user's wallpaper
最近我遇到了一种情况,我们需要使用 PowerShell 设置默认壁纸以及任何现有用户的壁纸。
我们可以通过替换文件 C:\Windows\Web\Wallpaper\Windows\img0.jpg 来设置默认壁纸,但我还没有找到合适的解决方案来替换任何现有的壁纸。
我考虑过/尝试过的一些事情:
- 从注册表设置墙纸。这样做的问题是为每个用户都这样做。
- 正在删除和复制 TranscodedWallpaper 文件。问题是 Windows 7 将文件命名为 TranscodedWallpaper.jpg,Windows 8 将其命名为 TranscodedWallpaper.bmp,而 Windows 10 只是 TranscodedWallpaper。虽然我想我们可以创建文件的三个不同版本并检查 OS 版本,但我更愿意在采用此路线之前验证没有其他解决方案。
我是不是完全漏掉了什么?有人对我们如何设置它有建议吗?
提前致谢!
经过一番尝试,这就是我的想法。我不是 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 建议。一般情况下,我肯定同意!
最近我遇到了一种情况,我们需要使用 PowerShell 设置默认壁纸以及任何现有用户的壁纸。
我们可以通过替换文件 C:\Windows\Web\Wallpaper\Windows\img0.jpg 来设置默认壁纸,但我还没有找到合适的解决方案来替换任何现有的壁纸。
我考虑过/尝试过的一些事情:
- 从注册表设置墙纸。这样做的问题是为每个用户都这样做。
- 正在删除和复制 TranscodedWallpaper 文件。问题是 Windows 7 将文件命名为 TranscodedWallpaper.jpg,Windows 8 将其命名为 TranscodedWallpaper.bmp,而 Windows 10 只是 TranscodedWallpaper。虽然我想我们可以创建文件的三个不同版本并检查 OS 版本,但我更愿意在采用此路线之前验证没有其他解决方案。
我是不是完全漏掉了什么?有人对我们如何设置它有建议吗?
提前致谢!
经过一番尝试,这就是我的想法。我不是 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 建议。一般情况下,我肯定同意!