Powershell - Change windows 7 background to image off a website

北城余情 提交于 2019-12-11 02:47:40

问题


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.


回答1:


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



回答2:


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:


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.



来源:https://stackoverflow.com/questions/8523181/powershell-change-windows-7-background-to-image-off-a-website

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!