DirectoryInfo dir = new DirectoryInfo(url);
if (!dir.Exists)
{
msg = "锁屏资源不存在!";
return false;
}
FileInfo[] fis = dir.GetFiles("*.*", SearchOption.TopDirectoryOnly);
if (fis.Length <= 0)
{
msg = "背景图资源不存在!";
return false;
int openOrCreate;
iRst = RegCloseKey(hKey); //最后记得关闭已打开的键
string sysBackgroundsDir = Environment.GetFolderPath(Environment.SpecialFolder.System)+ "\\oobe\\info\\backgrounds";
//string sysBackgroundsDir = "C:\\Windows\\System32\\oobe\\info\\backgrounds";
if (!Directory.Exists(sysBackgroundsDir))
{
DirectoryInfo di = Directory.CreateDirectory(sysBackgroundsDir);
}
if (!dir.Exists)
{
msg = "锁屏资源不存在!";
return false;
}
FileInfo[] fis = dir.GetFiles("*.*", SearchOption.TopDirectoryOnly);
if (fis.Length <= 0)
{
msg = "背景图资源不存在!";
return false;
}
int openOrCreate;
//WOW64_64Key起不被重定向作用
int iRst = RegCreateKeyEx(RegistryHive.LocalMachine, @"SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background",0,null,0,RegSAM.WOW64_64Key | RegSAM.Write, null, out hKey, out openOrCreate);
iRst = RegSetValueEx(hKey, "OEMBackground", 0, RegValueType.REG_DWORD, 1, 4);iRst = RegCloseKey(hKey); //最后记得关闭已打开的键
IntPtr oldWOW64State = new IntPtr();
Wow64DisableWow64FsRedirection(ref oldWOW64State);//关闭文件重定向
string sysBackgroundsDir = Environment.GetFolderPath(Environment.SpecialFolder.System)+ "\\oobe\\info\\backgrounds";
//string sysBackgroundsDir = "C:\\Windows\\System32\\oobe\\info\\backgrounds";
if (!Directory.Exists(sysBackgroundsDir))
{
DirectoryInfo di = Directory.CreateDirectory(sysBackgroundsDir);
}
File.Copy(fis[0].FullName, sysBackgroundsDir + "\\backgroundDefault.jpg", true);
Wow64RevertWow64FsRedirection(oldWOW64State);
本文介绍了一种通过编程方式设置Windows系统锁屏背景的方法。首先检查目标文件夹是否存在锁屏资源,接着使用注册表API启用自定义背景功能,并将指定图片复制到系统背景文件夹中以实现锁屏背景的更换。
547

被折叠的 条评论
为什么被折叠?



