我使用的操作系统是Windows 10。我想通过脚本或其他编程方式更改桌面壁纸和锁屏幻灯片的相册。我研究过更改regedit设置,但在regedit直接引用专辑目录的内容中找不到任何内容。
到目前为止,我已经查看HKEY_CURRENT_USER\Control Panel\Desktop并发现当前的壁纸图片存储在%APPDATA%\Microsoft\Windows\Themes\TranscodedWallpaper其中,并且幻灯片的元素被编码在slideshow.ini该目录中的隐藏文件中。
我再次想找到一种以编程方式更改此设置的方法。
所以...我正在使用 Windows 7。目前,以下内容似乎对我有用:
首先,您要根据需要设置幻灯片,然后保存文件的备份
%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Themes\slideshow.ini
Run Code Online (Sandbox Code Playgroud)
据我所知,这对专辑文件夹路径进行了编码。可能有一种方法可以构建您自己的,但目前我不知道。
我正在使用 powershell。我的 powershell 执行以下操作:
根据此处的代码定义一个设置壁纸的函数:
Add-Type @"
using System;
using System.Runtime.InteropServices;
using Microsoft.Win32;
namespace Wallpaper {
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 lpvPara, int fuWinIni);
public static void SetWallpaper (string path) {
SystemParametersInfo(SetDesktopWallpaper, 0, path, UpdateIniFile | SendWinIniChange);
RegistryKey key = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop", true);
//"Fit" style
key.SetValue(@"WallpaperStyle", "6");
key.SetValue(@"TileWallpaper", "0");
key.Close();
}
}
}
"@
[Wallpaper.Setter]::SetWallpaper("C:\My\Cool\Pics\monkey.jpg")
Run Code Online (Sandbox Code Playgroud)
总代码可能太长,但要点如下:
slideshow.ini回该目录Stop-process -name explorer 〜\AppData\Roaming\Microsoft\Windows\Themes\slideshow.ini
〜\ AppData \ Roaming \ Microsoft \ Windows \ Themes \ TranscodedImage.jpg
Stop-process -name explorer关于文件的编码slideshow.ini:根据此论坛对话,编码字段是“uuencoded PCIDLIST_ABSOLUTE struct”。我还没有研究过这个,但也许有人可以弄清楚如何创建它们。
关于杀死探险家。在我的机器上,资源管理器在重新启动后需要几秒钟的时间才能启动幻灯片,但据我所知,它似乎一直在工作。我已经尝试了几种替代方法,但我无法找到一种更干净的方法来刷新桌面并获取新设置。当 explorer.exe 读取一些相关的注册表项时,我可以在 SysInternals procmon 中看到。看起来像是在初始化系统托盘期间或之后。
我不知道半频繁地杀死资源管理器对您的系统有多么糟糕。也许情况很糟糕?如果您找到更好的方法,请分享。:)
| 归档时间: |
|
| 查看次数: |
3721 次 |
| 最近记录: |