Last active
November 25, 2021 08:56
-
-
Save bestK/3e5dd33d16943cfb1753023c2129b5f2 to your computer and use it in GitHub Desktop.
windows 自动换墙纸
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 获取图片 可自行替换图片接口 | |
Function Save-TodayImage() | |
{ | |
$imgLink = 'https://api.ixiaowai.cn/gqapi/gqapi.php' | |
$imageDir = "$HOME\Pictures\Bing\" | |
if( -not (Test-Path $imageDir) ) | |
{ | |
mkdir $imageDir | Out-Null | |
} | |
$imageFile = Join-Path $imageDir ( '{0}.jpg' -f (([DateTime]::Now.ToUniversalTime().Ticks - 621355968000000000)/10000000).tostring().Substring(0,10)) | |
Invoke-WebRequest -Uri $imgLink -OutFile $imageFile | |
return $imageFile | |
} | |
# 赋值图片路径 | |
$image = Save-TodayImage | |
$code = @' | |
using System.Runtime.InteropServices; | |
namespace Win32{ | |
public class Wallpaper{ | |
[DllImport("user32.dll", CharSet=CharSet.Auto)] | |
static extern int SystemParametersInfo (int uAction , int uParam , string lpvParam , int fuWinIni) ; | |
public static void SetWallpaper(string thePath){ | |
SystemParametersInfo(20,0,thePath,3); | |
} | |
} | |
} | |
'@ | |
add-type $code | |
# 替换墙纸 直接使用 rundll32.exe user32.dll updateperusersystemparameters 会经常失败 参考 https://c-nergy.be/blog/?p=15291 | |
[Win32.Wallpaper]::SetWallpaper($image) | |
# 墙纸自动替换教程 https://c-nergy.be/blog/?p=15291 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
test