power shell 设置壁纸

SetWall.ps1:

$imgPath="C:\Users\ajanuw\Pictures\Saved Pictures\1.jpg"

$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 
[Win32.Wallpaper]::SetWallpaper($imgPath)
posted @ 2021-04-15 10:02  Ajanuw  阅读(83)  评论(0编辑  收藏  举报