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

 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);
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值