PowerShell-更改Windows 7背景以显示网站上的图像 [英] Powershell - Change windows 7 background to image off a website

查看:5
本文介绍了PowerShell-更改Windows 7背景以显示网站上的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

set-itemproperty -path "HKCU:Control PanelDesktop" -name WallPaper -value Zapotec.bmp

我在网上为PowerShell for Windows7找到了这段代码,但我希望将墙纸设置为存储在Web服务器上的文件,该文件可以通过浏览器访问。我该如何着手做这件事。

推荐答案

我试图使用您的命令更改我的墙纸,但在我运行以下命令之前无效:rundll32.exe user32.dll,UpdatePerUserSystemParameters。即使在那时,它也只是间歇性地工作(这在Win7上是一个已知的问题)。

总之,我已经为PowerShell编写了一个将源URL下载到磁盘的getfile函数。

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()
    }
}

您可以找到它和一个更简单的版本here,以及它正在做什么的详细说明。

您应该可以像这样更换墙纸:

$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 PanelDesktop" -name WallPaper -value $filename
rundll32.exe user32.dll, UpdatePerUserSystemParameters

这篇关于PowerShell-更改Windows 7背景以显示网站上的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆