IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    Windows 自动设置开机锁屏壁纸 V3

    est发表于 2025-04-25 23:49:00
    love 0

    之前也写过,Windows下自动设置墙纸 V1,V2,今天发现两种方法都失效了。

    于是一气之下搞了个 Bing Image of the Day 版本的。

    保存为 change_wallpaper.bat 双击执行。加入自启动或者定时触发。

    @if (@X)==(@Y) @end /* set Win10 wallpaper to Bing Image of The Day. By est.im
    @echo off
    cscript //Nologo //U //E:JScript "%~F0"
    exit /b %errorlevel%
    */
    
    function http_get(url){
      var xhr = new ActiveXObject("MSXML2.XMLHTTP")
      xhr.open("GET", url, false)
      xhr.setRequestHeader("Accept-Encoding", "identity")
      xhr.send()
      return xhr
    }
    
    var rss_req = http_get('https://www.bing.com/HPImageArchive.aspx?format=rss&idx=0&n=1&mkt=en-US')
    // WScript.Echo(rss_req.getAllResponseHeaders())
    var img_url = 'https://www.bing.com' + rss_req.responseXML.selectSingleNode("//rss/channel/item/link").text
    WScript.echo(img_url)
    var fso = new ActiveXObject("Scripting.FileSystemObject")  // shit cant handle binary data
    var stream = new ActiveXObject("ADODB.Stream")
    var img_path = fso.GetSpecialFolder(2)+"\\bing_iotd.jpg"
    WScript.echo(img_path)
    stream.Open()
    stream.Type = 1
    var img_req = http_get(img_url)
    stream.Write(img_req.responseBody)
    stream.SaveToFile(img_path, 2)
    stream.Close()
    
    var WshShell = new ActiveXObject("WScript.Shell")  
    WshShell.RegWrite("HKEY_CURRENT_USER\\Control Panel\\Desktop\\Wallpaper", img_path, "REG_SZ")
    WshShell.Run("RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters")
    

    其中 format=rss 可以改成 =js 或者 =xml 本来想解析 json 但是发现老的 IE6 引擎不能支持双引号这种JSON,而且只能用 eval() 就放弃了。还好有 xpath 还挺方便。

    要用 .bat 套一层是因为 win10 貌似禁止 .js 或者 .vbs 双击执行了。病毒木马太多了。这种一份源码同时被两种语言解析还有点技巧可以参考下。

    很久没写 .jscript 了用了 ChatGPT 这个 vibe coding 真爽。



沪ICP备19023445号-2号
友情链接