其实只不过是利用了win32函数
function Set-Wallpaper($image){ $source = @" using System; using System.Runtime.InteropServices; public class Params { [DllImport("User32.dll",CharSet=CharSet.Unicode)] public static extern int SystemParametersInfo (Int32 uAction, Int32 uParam, String lpvParam, Int32 fuWinIni); } "@ Add-Type -TypeDefinition $source $SPI_SETDESKWALLPAPER = 0x0014 $UpdateIniFile = 0x01 $SendChangeEvent = 0x02 $fWinIni = $UpdateIniFile -bor $SendChangeEvent $ret = [Params]::SystemParametersInfo($SPI_SETDESKWALLPAPER, 0, $Image, $fWinIni) } Set-Wallpaper '图片路径'
本文介绍了一种使用PowerShell脚本和Win32 API函数SystemParametersInfo来更改Windows桌面壁纸的方法。通过定义一个名为Set-Wallpaper的函数,可以接受图片路径作为参数并将其设为桌面背景。
387

被折叠的 条评论
为什么被折叠?



