Powershell - Change windows 7 background to image

2019-07-21 16:06发布

set-itemproperty -path "HKCU:Control Panel\Desktop" -name WallPaper -value Zapotec.bmp

I found this code online for Powershell for windows 7, however I want the wallpaper to be set to a file stored on a webserver accessible from a browser. how would i go about doing this.

3条回答
三岁会撩人
2楼-- · 2019-07-21 16:33

I'm pretty sure you can't do this. Wallpaper images must be locally stored. When you right click on an image in a browser and "set as wallpaper" it is copied to your hard disk.

查看更多
太酷不给撩
3楼-- · 2019-07-21 16:38

I think you have 2 options.

  1. Have Powershell download the file locally and use p/invoke to call the SystemParametersInfo function in User32.dll to set the wallpaper. The API will set it and activate the change immediately. Here's an example of doing that.

  2. Use RSS wallpaper theme. You can edit a .theme file and specify your own RSS URL, however the feed URL needs to have a media item for the images like this one. You can download this theme file and edit it with your RSS feed URL.

查看更多
淡お忘
4楼-- · 2019-07-21 16:47

I tried to change my wallpaper with your command but it didn't work until I ran this: rundll32.exe user32.dll, UpdatePerUserSystemParameters. Even then, it only worked intermittently (it's a know issue on Win7).

Anyways, I have written a getfile function for PowerShell that downloads a source url to the disk.

function getfile($url, $filename)
{
    $wc = New-Object System.Net.WebClient

    Register-ObjectEvent -InputObject $wc -EventName DownloadProgressChanged -SourceIdentifier WebClient.DownloadProgressChanged -Action { Write-Progress -Activity "Downloading: $($EventArgs.ProgressPercentage)% Completed" -Status $url -PercentComplete $EventArgs.ProgressPercentage; }

    Register-ObjectEvent -InputObject $wc -EventName DownloadFileCompleted -SourceIdentifier WebClient.DownloadFileComplete -Action { Write-Host "Download Complete - $filename"; Unregister-Event -SourceIdentifier WebClient.DownloadProgressChanged; Unregister-Event -SourceIdentifier WebClient.DownloadFileComplete; }

    try
    {
        $wc.DownloadFileAsync($url, $filename)
    }
    catch [System.Net.WebException]
    {
        Write-Host("Cannot download $url")
    } 
    finally
    {   
        $wc.Dispose()
    }
}

You can find it and a simpler version here along with a detailed description of what it is doing.

You should be able to change your wallpaper with some thing like this:

$url = "http://fc05.deviantart.net/fs30/f/2008/062/9/4/Serenity_WPP3___1920_Preview_by_nuaHs.jpg"
$filename = "d:\serenity.jpg"
getfile $url $filename
set-itemproperty -path "HKCU:Control Panel\Desktop" -name WallPaper -value $filename
rundll32.exe user32.dll, UpdatePerUserSystemParameters
查看更多
登录 后发表回答