{"id":380,"date":"2022-02-26T00:01:35","date_gmt":"2022-02-25T16:01:35","guid":{"rendered":"http:\/\/benson.ml\/?p=380"},"modified":"2022-03-23T13:12:57","modified_gmt":"2022-03-23T05:12:57","slug":"%e4%bd%bf%e7%94%a8powershell%e8%87%aa%e5%8a%a8%e8%ae%be%e7%bd%ae%e5%a3%81%e7%ba%b8","status":"publish","type":"post","link":"https:\/\/benson80.eu.org\/?p=380","title":{"rendered":"\u4f7f\u7528Powershell\u81ea\u52a8\u8bbe\u7f6e\u58c1\u7eb8"},"content":{"rendered":"\n<p>\u53d1\u73b0CMD\u4e0d\u80fd\u8fbe\u5230\u6b64\u76ee\u7684\uff0c\u66f4\u6362\u66f4\u9ad8\u7ea7\u7684Powershell\u6765\u6267\u884c\u8fd9\u4e2a\u4efb\u52a1~<\/p>\n\n\n\n<p>\u6700\u8fd1\u6709\u7684\u4eba\u7ecf\u5e38\u66f4\u6362\u7535\u8111\u684c\u9762\u58c1\u7eb8\uff0c\u800c\u4e14\u58c1\u7eb8\u6211\u89c9\u5f97\u4e5f\u4e0d\u7b97\u597d\u770b(\u5f88\u96be\u770b)\uff0c\u57fa\u672c\u4e0a\u5c31\u662f\u8d77\u5230\u54d7\u4f17\u53d6\u5ba0\u7684\u76ee\u7684\uff0c\u6240\u4ee5\u6211\u6253\u7b97\u5229\u7528\u811a\u672c\u81ea\u52a8\u5b9a\u65f6\u66f4\u6362\u7535\u8111\u58c1\u7eb8\uff0c\u8fbe\u5230\u9501\u5b9a\u7535\u8111\u58c1\u7eb8\u7684\u76ee\u7684\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u51c6\u5907\u5de5\u4f5c\"><a href=\"https:\/\/huuhghhgyg.github.io\/2019\/03\/15\/PowershellSetWallpaper\/index.html#%E5%87%86%E5%A4%87%E5%B7%A5%E4%BD%9C\"><\/a>\u51c6\u5907\u5de5\u4f5c<\/h2>\n\n\n\n<p>\u5b66\u6821\u7684\u7535\u8111\u7cfb\u7edf\u662fWin7,\u9ed8\u8ba4\u8bbe\u7f6e\u4e0d\u5141\u8bb8\u6267\u884c\u811a\u672c(\u4e0d\u77e5\u9053\u662f\u4e0d\u662fGhost\u7cfb\u7edf\u7684\u4eba\u8bbe\u7f6e\u7684)\uff0c\u6240\u4ee5\u7b2c\u4e00\u6b65\u8981\u89e3\u9664\u9650\u5236\u3002<br>Powershell\u4e2d\u6267\u884c\u547d\u4ee4\u5982\u4e0b:<br><code>Set-ExecutionPolicy Unrestricted<\/code><br>\u6267\u884c\u5b8c\u6bd5\u4e4b\u540e\u5c31\u80fd\u8fd0\u884c<code>.ps1<\/code>\u811a\u672c\u4e86\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u81ea\u52a8\u66f4\u6362\u58c1\u7eb8\u7684\u51fd\u6570\u65b9\u6cd5\"><a href=\"https:\/\/huuhghhgyg.github.io\/2019\/03\/15\/PowershellSetWallpaper\/index.html#%E8%87%AA%E5%8A%A8%E6%9B%B4%E6%8D%A2%E5%A3%81%E7%BA%B8%E7%9A%84%E5%87%BD%E6%95%B0%E6%96%B9%E6%B3%95\"><\/a>\u81ea\u52a8\u66f4\u6362\u58c1\u7eb8\u7684\u51fd\u6570\u65b9\u6cd5<\/h2>\n\n\n\n<p>\u4fdd\u5b58\u5982\u4e0b\u4ee3\u7801\u5230\u4e00\u4e2a<code>.ps1<\/code>\u6587\u4ef6\u4e2d\u3002(\u53ef\u4ee5\u7528\u8bb0\u4e8b\u672c\u7f16\u8f91\u518d\u66f4\u6539\u6587\u4ef6\u62d3\u5c55\u540d)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Function Set-WallPaper($Value)\n{\n Set-ItemProperty -path 'HKCU:\\Control Panel\\Desktop\\' -name wallpaper -value $value\n rundll32.exe user32.dll, UpdatePerUserSystemParameters 1, True\n}\n\nSet-WallPaper -value \"C:\\Windows\\Web\\Wallpaper\\Homes_Background.bmp\"<\/code><\/pre>\n\n\n\n<p>\u5c06\u5176\u4e2d<code>C:\\Windows\\Web\\Wallpaper\\Homes_Background.bmp<\/code>\u66f4\u6539\u6210\u58c1\u7eb8\u6240\u5728\u5904\uff0c\u6267\u884c\u811a\u672c\u5373\u751f\u6548\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u6dfb\u52a0\u5230\u8ba1\u5212\u4efb\u52a1\">\u6dfb\u52a0\u5230\u8ba1\u5212\u4efb\u52a1<\/h2>\n\n\n\n<p>\u8ba1\u5212\u4efb\u52a1\u7684\u4f4d\u7f6e\u5728\u00a0<strong>\u201c\u63a7\u5236\u9762\u677f\u201d-(\u201c\u7cfb\u7edf\u548c\u5b89\u5168\u201d)-\u201c\u7ba1\u7406\u5de5\u5177\u201d-\u201c\u8ba1\u5212\u4efb\u52a1\u201d<\/strong><br>\u6253\u5f00\u540e\u70b9\u51fb\u00a0<strong>\u201c\u6dfb\u52a0\u57fa\u672c\u4efb\u52a1\u201d<\/strong>\u00a0,\u4e4b\u540e\u5c31\u53ef\u4ee5\u8ddf\u7740\u5411\u5bfc\u8d70\u4e86\u3002\u6267\u884c\u6587\u4ef6\u586b\u5199\u00a0<strong>powershell<\/strong>\u00a0,\u53c2\u6570\u586b\u5199\u521a\u521a\u4fdd\u5b58\u7684\u811a\u672c\u6587\u4ef6\u4f4d\u7f6e\u5373\u53ef\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"589\" height=\"422\" src=\"http:\/\/benson.ml\/wp-content\/uploads\/2022\/02\/image-1.png\" alt=\"\" class=\"wp-image-382\" srcset=\"https:\/\/benson80.eu.org\/wp-content\/uploads\/2022\/02\/image-1.png 589w, https:\/\/benson80.eu.org\/wp-content\/uploads\/2022\/02\/image-1-300x215.png 300w, https:\/\/benson80.eu.org\/wp-content\/uploads\/2022\/02\/image-1-419x300.png 419w\" sizes=\"auto, (max-width: 589px) 100vw, 589px\" \/><figcaption>\u8fd8\u53ef\u4ee5<br><strong>\u6bcf\u65e5\u83b7\u53d6Bing\u56fe\u7247\u5e76\u8bbe\u4e3a\u58c1\u7eb8<\/strong><\/figcaption><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>function Save-BingTodayImage()\n{\n    #\u5fc5\u5e94\u56fe\u7247\u6545\u4e8bAPI\n    $bingImageApi ='http:\/\/www.bing.com\/HPImageArchive.aspx?format=xml&amp;idx=0&amp;n=1&amp;mkt=zh-cn'\n    $bingUri = 'http:\/\/www.bing.com\/'\n \n    # \u83b7\u53d6\u56fe\u7247\u94fe\u63a5\n    &#91;xml]$bingImageXml = (Invoke-WebRequest -Uri $bingImageApi).Content\n    Write-Host \" \u4eca\u65e5\u56fe\u7247\u6545\u4e8b\uff1a $( $bingImageXml.images.image.copyright ) \"\n    $imgLink = '{0}{1}' -f $bingUri , $bingImageXml.images.image.url\n \n    # \u4e0b\u8f7d\u548c\u4fdd\u5b58\u56fe\u7247\n    $imageDir = \"$HOME\\Pictures\\Bing\\\"\n    if( -not (Test-Path $imageDir) )\n    {\n        mkdir $imageDir | Out-Null\n    }\n    $imageFile = Join-Path $imageDir ( '{0}.jpg' -f $bingImageXml.images.image.fullstartdate)\n \n    Invoke-WebRequest -Uri $imgLink -OutFile $imageFile\n \n    return $imageFile\n}\n \nFunction Set-DesktopWallPaper($imagePath)\n{\n Set-ItemProperty -path 'HKCU:\\Control Panel\\Desktop\\' -name wallpaper -value $imagePath\n RUNDLL32.EXE USER32.DLL UpdatePerUserSystemParameters ,1 ,True\n}\n \n# \u83b7\u53d6\u4eca\u65e5\u5fc5\u5e94\u80cc\u666f\u56fe\u7247\n$image=Save-BingTodayImage\n \n#\u8bbe\u7f6e\u4e3a\u684c\u9762\u5899\u7eb8\nSet-DesktopWallPaper -imagePath $image<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u53d1\u73b0CMD\u4e0d\u80fd\u8fbe\u5230\u6b64\u76ee\u7684\uff0c\u66f4\u6362\u66f4\u9ad8\u7ea7\u7684Powers &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-380","post","type-post","status-publish","format-standard","hentry","category-windows"],"_links":{"self":[{"href":"https:\/\/benson80.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/380","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=380"}],"version-history":[{"count":1,"href":"https:\/\/benson80.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/380\/revisions"}],"predecessor-version":[{"id":383,"href":"https:\/\/benson80.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/380\/revisions\/383"}],"wp:attachment":[{"href":"https:\/\/benson80.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=380"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/benson80.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=380"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/benson80.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=380"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}