代码片段 Powershell修改桌面壁纸

其实只不过是利用了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修改桌面壁纸)