天天看點

代碼片段 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 '图片路径'      

 

转载于:https://www.cnblogs.com/yinghualuowu/p/11418577.html