{"id":3316,"date":"2023-09-14T15:59:28","date_gmt":"2023-09-14T07:59:28","guid":{"rendered":"https:\/\/benson80.eu.org\/?p=3316"},"modified":"2023-09-14T16:13:43","modified_gmt":"2023-09-14T08:13:43","slug":"%e9%9a%8f%e6%9c%ba%e6%98%be%e7%a4%babing%e5%a3%81%e7%ba%b8","status":"publish","type":"post","link":"https:\/\/benson80.eu.org\/?p=3316","title":{"rendered":"\u968f\u673a\u663e\u793aBing\u58c1\u7eb8"},"content":{"rendered":"\n<p>\u684c\u9762\u65b0\u5efa\u4e00\u4e2a\u968f\u673a\u663e\u793a\u684c\u9762.ps1\u6587\u4ef6\uff0c\u5177\u4f53\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p># \u521b\u5efa\u4e00\u4e2a\u76ee\u5f55\u6765\u5b58\u50a8\u58c1\u7eb8<\/p>\n\n\n\n<p>$downloadPath = &#8220;$env:USERPROFILE\\BingWallpapers&#8221;<br>New-Item -ItemType Directory -Force -Path $downloadPath | Out-Null<\/p>\n\n\n\n<p># \u6784\u5efaBing\u58c1\u7eb8\u7684URL<\/p>\n\n\n\n<p>$bingURL = &#8220;https:\/\/www.bing.com&#8221;<br>$bingWallpaperURL = &#8220;$bingURL\/HPImageArchive.aspx?format=js&amp;idx=0&amp;n=8&amp;mkt=en-US&#8221; # \u8fd9\u91cc\u83b7\u53d6\u4e86\u6700\u8fd18\u5929\u7684\u58c1\u7eb8<\/p>\n\n\n\n<p># \u53d1\u9001HTTP\u8bf7\u6c42\u4ee5\u83b7\u53d6\u58c1\u7eb8\u4fe1\u606f<\/p>\n\n\n\n<p>$response = Invoke-RestMethod -Uri $bingWallpaperURL<\/p>\n\n\n\n<p># \u89e3\u6790JSON\u54cd\u5e94\u5e76\u83b7\u53d6\u58c1\u7eb8URL\u5217\u8868<\/p>\n\n\n\n<p>$wallpaperURLs = $response.images.url | ForEach-Object { $bingURL + $_ }<\/p>\n\n\n\n<p># \u968f\u673a\u9009\u62e9\u4e00\u4e2a\u58c1\u7eb8URL<\/p>\n\n\n\n<p>$randomWallpaperURL = $wallpaperURLs | Get-Random<\/p>\n\n\n\n<p># \u4f7f\u7528\u58c1\u7eb8URL\u7684\u54c8\u5e0c\u503c\u4f5c\u4e3a\u6587\u4ef6\u540d<\/p>\n\n\n\n<p>$wallpaperFileName = [System.Security.Cryptography.HashAlgorithm]::Create(&#8220;MD5&#8221;).ComputeHash([System.Text.Encoding]::UTF8.GetBytes($randomWallpaperURL)) | ForEach-Object { $_.ToString(&#8220;x2&#8221;) }<br>$wallpaperPath = Join-Path -Path $downloadPath -ChildPath &#8220;$wallpaperFileName.jpg&#8221;<\/p>\n\n\n\n<p># \u4e0b\u8f7d\u58c1\u7eb8<\/p>\n\n\n\n<p>Invoke-WebRequest -Uri $randomWallpaperURL -OutFile $wallpaperPath<\/p>\n\n\n\n<p># \u8bbe\u7f6e\u58c1\u7eb8<\/p>\n\n\n\n<p>Add-Type -TypeDefinition @&#8221;<br>using System;<br>using System.Runtime.InteropServices;<\/p>\n\n\n\n<p>public class Wallpaper {<br>[DllImport(&#8220;user32.dll&#8221;, CharSet = CharSet.Auto)]<br>public static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);<\/p>\n\n\n\n<p>public const int SPI_SETDESKWALLPAPER = 20;<br>public const int SPIF_UPDATEINIFILE = 0x01;<br>public const int SPIF_SENDCHANGE = 0x02;<\/p>\n\n\n\n<p>public static void SetWallpaper(string path) {<br>SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, path, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);<br>}<br>}<\/p>\n\n\n\n<p>&#8220;@<\/p>\n\n\n\n<p># \u663e\u793a\u58c1\u7eb8<\/p>\n\n\n\n<p>Invoke-Item $wallpaperPath<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u684c\u9762\u65b0\u5efa\u4e00\u4e2a\u968f\u673a\u663e\u793a\u684c\u9762.ps1\u6587\u4ef6\uff0c\u5177\u4f53\u4ee3\u7801\u5982\u4e0b &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-3316","post","type-post","status-publish","format-standard","hentry","category-windows"],"_links":{"self":[{"href":"https:\/\/benson80.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/3316","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/benson80.eu.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/benson80.eu.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/benson80.eu.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/benson80.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3316"}],"version-history":[{"count":1,"href":"https:\/\/benson80.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/3316\/revisions"}],"predecessor-version":[{"id":3317,"href":"https:\/\/benson80.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/3316\/revisions\/3317"}],"wp:attachment":[{"href":"https:\/\/benson80.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3316"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/benson80.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3316"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/benson80.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3316"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}