2016-08-17 63 views
0

最近我遇到了一個情況,我們需要使用PowerShell設置默認壁紙以及任何現有用戶的壁紙。更改所有用戶的壁紙

我們可以通過替換文件C:\ Windows \ Web \ Wallpaper \ Windows \ img0.jpg來設置默認壁紙,但我還沒有找到替換任何現有壁紙的合適解決方案。

有些事情我想過/試過:

  • 設置從註冊表中的牆紙。這個問題是爲每個用戶做的。
  • 刪除並複製TranscodedWallpaper文件。問題在於Windows 7命名文件TranscodedWallpaper.jpg,Windows 8命名爲TranscodedWallpaper.bmp,Windows 10命名爲TranscodedWallpaper。雖然我想我們可以創建三個不同版本的文件並檢查操作系統版本,但我寧願在採用此路由之前驗證沒有其他解決方案。

我完全錯過了什麼嗎?有人對我們如何設置這個建議有什麼建議嗎?

在此先感謝!

+0

如何使用GPO?組策略做了很多整潔的事情。 – TheMadTechnician

+0

完全同意,但我們並不總是知道這些計算機是否將使用GPO進行設置。我正在研究的東西是加載用戶配置單元。看起來很有希望。 –

+0

「使用GPO進行設置」是什麼意思?只需將計算機對象放入AD中相應的OU中,GPO就會自動應用。 –

回答

0

經過一番玩耍,這是我想出來的。我不是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的建議。一般情況下,我肯定會同意!