gpt4 book ai didi

powershell - Powershell-将Windows 7背景更改为网站图像

转载 作者:行者123 更新时间:2023-12-02 23:16:01 27 4
gpt4 key购买 nike

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

我在Windows 7的Powershell上在线找到了此代码,但是我希望将墙纸设置为存储在可通过浏览器访问的Web服务器上的文件。我将如何去做。

最佳答案

我尝试使用您的命令更改墙纸,但直到运行以下命令,该墙纸才起作用:rundll32.exe user32.dll,UpdatePerUserSystemParameters。即使这样,它也只能间歇性地工作(这是Win7上的已知问题)。

无论如何,我已经为PowerShell编写了一个getfile函数,该函数将源URL下载到磁盘上。

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

关于powershell - Powershell-将Windows 7背景更改为网站图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8523181/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com