Skip to content

Instantly share code, notes, and snippets.

@bestK
Last active November 25, 2021 08:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bestK/3e5dd33d16943cfb1753023c2129b5f2 to your computer and use it in GitHub Desktop.
Save bestK/3e5dd33d16943cfb1753023c2129b5f2 to your computer and use it in GitHub Desktop.
windows 自动换墙纸
# 获取图片 可自行替换图片接口
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
@bestK
Copy link
Author

bestK commented Nov 25, 2021

<script src="https://gist.github.com/bestK/3e5dd33d16943cfb1753023c2129b5f2.js"></script>

test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment