rundll32.exe user32.dll, UpdatePerUserSystemParameters
实际上并没有为我更改 2008 x64 盒子上的壁纸。但这确实做到了...它调用 Win32 API 来调用更改壁纸。如果您将其保存为 ChangeDesktop.ps1 脚本,它应该可以工作。如下所示,它将删除所有桌面壁纸。但是,如果您确实想设置一个,可以使用受支持的图像文件的路径编辑最后一行,如下所示:
[Wallpaper.Setter]::SetWallpaper( 'C:\Wallpaper.bmp', 0 )
第二个参数是样式:
0:平铺
1:中心
2:拉伸
3:没有变化
剧本:
Add-Type @"
using System;
using System.Runtime.InteropServices;
using Microsoft.Win32;
namespace Wallpaper
{
public enum Style : int
{
Tile, Center, Stretch, NoChange
}
public class Setter {
public const int SetDesktopWallpaper = 20;
public const int UpdateIniFile = 0x01;
public const int SendWinIniChange = 0x02;
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern int SystemParametersInfo (int uAction, int uParam, string lpvParam, int fuWinIni);
public static void SetWallpaper ( string path, Wallpaper.Style style ) {
SystemParametersInfo( SetDesktopWallpaper, 0, path, UpdateIniFile | SendWinIniChange );
RegistryKey key = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop", true);
switch( style )
{
case Style.Stretch :
key.SetValue(@"WallpaperStyle", "2") ;
key.SetValue(@"TileWallpaper", "0") ;
break;
case Style.Center :
key.SetValue(@"WallpaperStyle", "1") ;
key.SetValue(@"TileWallpaper", "0") ;
break;
case Style.Tile :
key.SetValue(@"WallpaperStyle", "1") ;
key.SetValue(@"TileWallpaper", "1") ;
break;
case Style.NoChange :
break;
}
key.Close();
}
}
}
"@
[Wallpaper.Setter]::SetWallpaper( '', 0 )
最初来自 PoshCode:http://poshcode.org/491 http://poshcode.org/491