您的位置:首页 > 编程语言 > C#

C# Windows7锁屏设置图片路径 修改注册表

2018-03-20 15:05 323 查看
 DirectoryInfo dir = new DirectoryInfo(url);
            if (!dir.Exists)
            {
                msg = "锁屏资源不存在!";
                return false;
            }
            FileInfo[] fis = dir.GetFiles("*.*", SearchOption.TopDirectoryOnly);
            if (fis.Length <= 0)
            {
                msg = "背景图资源不存在!";
                return false;
            }

            UIntPtr hKey;
            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);//关闭文件重定向

          // 把图片“backgroundDefault.jpg”放到目录“%windir%\system32\oobe\info\backgrounds\”里。
 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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: