有关为何在PS中运行w /的原因有任何想法和建议,但在从定义为:
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -File "C:\Users\bin\ChangeDesktop.ps1"
Run Code Online (Sandbox Code Playgroud)
ChangeDesktop.ps1的内容:
set-itemproperty -path "HKCU:Control Panel\Desktop" -name WallPaper -value ""
rundll32.exe user32.dll, UpdatePerUserSystemParameters
Run Code Online (Sandbox Code Playgroud)
如果我在PS"命令提示符"环境中,桌面背景将自动删除并刷新,除此之外我必须手动刷新桌面以实现更改.
系统是Windows Server 2008 R2 - 全新安装.脚本executionpolicy设置为RemoteSigned,我没有看到任何PS错误.我从桌面快捷方式运行时看不到桌面自动刷新.
划痕头
And*_*ndi 28
rundll32.exe user32.dll, UpdatePerUserSystemParameters实际上并没有在2008 x64盒子上为我更换壁纸.虽然这样做...它调用Win32 API来调用更改壁纸.如果将其保存为ChangeDesktop.ps1脚本,它应该可以正常工作.因为它在下面它将删除任何桌面壁纸.但是,如果您确实要设置一个,则可以使用支持的图像文件的路径编辑最后一行,如下所示:
[Wallpaper.Setter]::SetWallpaper( 'C:\Wallpaper.bmp', 0 )
Run Code Online (Sandbox Code Playgroud)
第二个参数是造型:
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 )
Run Code Online (Sandbox Code Playgroud)
最初来自PoshCode:http://poshcode.org/491
| 归档时间: |
|
| 查看次数: |
45623 次 |
| 最近记录: |