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);