找回密码
 立即注册
首页 业界区 安全 【简单壁纸】:通过右键切换本地、联网下载壁纸 ...

【简单壁纸】:通过右键切换本地、联网下载壁纸

堵赫然 2025-6-25 13:58:30
简介

右键简单壁纸(或 简单壁纸)是一款轻量级批处理桌面壁纸管理工具,通过在桌面右键菜单集成丰富的壁纸功能,无后台进程,让您无需打开应用即可快速更换、下载和管理壁纸。
1.gif

2.png

主要特性:

  • 支持桌面右键一键切换壁纸:上一张、下一张、随机、最新。
  • 自动定时更换壁纸(可自定义频率)。
  • 下载必应每日壁纸并自动设置为桌面背景。
  • 支持必应每日壁纸的定时任务下载
  • 支持自定义壁纸目录。
  • 提供快捷打开壁纸目录、应用安装目录、清理日志等功能。
无需安装额外依赖,仅依赖系统自带的 cmd、PowerShell、VBS、curl 等工具。
下载

您可以在以下渠道下载:
蓝奏云:
https://wwqn.lanzoul.com/b0fplbuoh
密码:8zut
安装

如果已经安装请先卸载原应用,避免版本冲突。
以管理员身份运行 右键简单壁纸.bat,选择 1 进行安装。
安装完成后,右键桌面空白处,即可看到 简单壁纸 菜单。
第一次使用请先“设置壁纸目录”,让 简单壁纸 知道你的本地壁纸或联网下载的壁纸保存的位置。
安装目录默认为 %LOCALAPPDATA%\SimpleWallpaper,配置文件为 smw_config.ini。
使用

右键桌面空白处,您会看到 简单壁纸 菜单,支持以下功能:

  • 上一张 / 下一张:在指定壁纸目录中按文件顺序切换壁纸,支持循环切换。
  • 随机:随机选择一张壁纸。
  • 最新:选用最新下载或加入目录的壁纸。
  • 自动更换:设置壁纸自动更换频率,可选 1 分钟至 12 小时。
  • 联网壁纸

    • 下载必应壁纸:手动下载最新必应壁纸,会下载必应最新的15张壁纸,如果是第一次运行请耐心下载壁纸完成的提示,下载完成后会自动切换下载的壁纸。
    • 必应每日一图:开启或关闭自动每日下载必应壁纸。

  • 设置

    • 设置壁纸目录、打开壁纸目录、打开应用目录。
    • 清理日志(默认不开启,仅开发模式使用)。
    • 卸载。

卸载

右键桌面空白处 -> 简单壁纸 -> 设置 -> 卸载
或以管理员身份运行脚本选择 2. 卸载。
卸载操作会:

  • 删除右键菜单相关注册表。
  • 删除安装目录。
  • 删除相关任务计划。
日志

如需启用日志,请在配置文件中将 smw_log=1,日志文件默认位于 %LOCALAPPDATA%\SimpleWallpaper\log\smw.log。
后续


  • 支持更多壁纸源 ?
  • 支持自定义安装目录 ?
  • 删除不喜欢的壁纸?
注意事项

必须以管理员权限运行以正常注册右键菜单。
本脚本不修改系统安全策略,但请确保防火墙或安全软件允许脚本访问必应等外网服务以下载壁纸。
脚本会在系统任务计划中注册任务用于自动壁纸切换或下载,如需手动管理可在任务计划程序中查看或修改。
源码

因为代码可能会不断更新,下面的代码为1.5版本的,仅供参考。你可以下载最新的文件查看最新的代码。
  1. @echo off & chcp 65001>nul & setlocal EnableDelayedExpansion
  2. net session >nul 2>&1 || (echo 请以管理员身份运行 & pause>nul)
  3. :: 初始化一些必要参数
  4. set "appName=SimpleWallpaper"
  5. set "appNameCN=简单壁纸"
  6. set "installDir=%LOCALAPPDATA%\%appName%"
  7. set "configFile=%installDir%\smw_config.ini"
  8. set "vbsPath=%installDir%\%appName%.vbs"
  9. set "requiredParams=smw_wallpaperPath smw_auto_change smw_day_bing_wallpaper smw_log"
  10. set "app_regedit=HKCR\DesktopBackground\shell\wallpaper"
  11. set "autoChangeTaskName=自动更换背景"
  12. set "dayBingWallpaperTaskName=必应每日一图"
  13. :: 手动运行/右键运行
  14. for %%i in (%*) do (set /a PIndex+=1 & call set "param[!PIndex!]=%%~i")
  15. if not defined param[1] (goto :human_menu) else (goto :cmd_menu)
  16. :human_menu
  17. mode con cols=90 lines=35 & color 0A & title 右键%appNameCN% v1.5
  18. set "c=" &echo.&echo.&echo.
  19. echo                                            右键%appNameCN%        &echo.&echo.&echo.
  20. echo                                1. 安装      2. 卸载      0.退出&echo.&echo.&echo.   
  21. set /p c=请输入你的选择:
  22. if "%c%"=="1"  call :install
  23. if "%c%"=="2"  call :uninstall
  24. if "%c%"=="0" exit
  25. goto human_menu
  26. :cmd_menu
  27. call :init_app
  28. call :print_log "执行命令:%param[1]%"
  29. if "%param[1]%"=="prev" call :choose_wallpaper
  30. if "%param[1]%"=="next" call :choose_wallpaper
  31. if "%param[1]%"=="rand" call :choose_wallpaper
  32. if "%param[1]%"=="latest" call :choose_wallpaper
  33. if "%param[1]%"=="uninstall" call :uninstall
  34. if "%param[1]%"=="auto" call :auto
  35. if "%param[1]%"=="set_wallpaperPath" call :set_wallpaperPath
  36. if "%param[1]%"=="open_wallpaperPath" call :open_wallpaperPath
  37. if "%param[1]%"=="open_installDir" call :open_installDir
  38. if "%param[1]%"=="load_bing_wallpaper" call :load_bing_wallpaper
  39. if "%param[1]%"=="day_bing_wallpaper" call :day_bing_wallpaper
  40. if "%param[1]%"=="toggle_auto_change" call :toggle_auto_change
  41. call :print_log "---------end---------"
  42. exit
  43. :init_app
  44. for /f "usebackq eol=# tokens=1,* delims==" %%a in (%configFile%) do set "%%a=%%b"
  45. call :print_log "---------start---------"
  46. call :print_log "加载配置文件..."
  47. for %%p in (%requiredParams%) do (if not defined %%p (call :print_log 缺少参数%%p & exit) else (set "tv=!%%p!" & call :print_log "%%p=!tv!"))
  48. for /f "tokens=1,2,*" %%a in ('reg query "HKCU\Control Panel\Desktop" /v Wallpaper ^| findstr /i "Wallpaper"') do (
  49.         set "current_wallpaper=%%~c"
  50.         call :print_log "当前壁纸路径: !current_wallpaper!"
  51. )
  52. exit /b
  53. :install
  54. if not exist "%installDir%" mkdir "%installDir%"
  55. if not exist "%installDir%\log" mkdir "%installDir%\log"
  56. :: 设置壁纸下载位置
  57. for /f "usebackq delims=" %%P in (`powershell -nologo -noprofile -command "[Environment]::GetFolderPath('MyPictures')"`) do (
  58.         set "smw_wallpaperPath=%%P\%appName%"
  59. )
  60. :: 必应每日一图 0关闭 1开启
  61. set "smw_day_bing_wallpaper=0"
  62. :: 自己换图 0关闭 1开启
  63. set "smw_auto_change=0"
  64. :: 日志记录 0关闭 1开启
  65. set "smw_log=0"
  66. call :save_config
  67. copy /y "%~f0" "%installDir%\%appName%.bat" >nul
  68. (        echo Set shell = CreateObject("Shell.Application"^)
  69.         echo Set fso = CreateObject("Scripting.FileSystemObject"^)
  70.         echo scriptDir = fso.GetParentFolderName(WScript.ScriptFullName^)
  71.         echo args = ""
  72.         echo For i = 0 To WScript.Arguments.Count - 1
  73.         echo     args = args ^& " " ^& Chr(34^) ^& WScript.Arguments(i^) ^& Chr(34^)
  74.         echo Next
  75.         echo shell.ShellExecute "cmd.exe", "/c cd /d """ ^& scriptDir ^& """ && %appName%.bat" ^& args, "", "runas", 0
  76. ) > "%vbsPath%"
  77. call :print_log "安装%appNameCN% start"
  78. reg add "%app_regedit%" /v "MUIVerb" /t REG_SZ /d "%appNameCN%" /f >nul 2>&1
  79. reg add "%app_regedit%" /v "Icon" /t REG_SZ /d "imageres.dll,-113" /f >nul 2>&1
  80. reg add "%app_regedit%" /v "SubCommands" /t REG_SZ /d "" /f >nul 2>&1
  81. reg add "%app_regedit%\shell\1_pre" /v "MUIVerb" /t REG_SZ /d "上一张" /f >nul 2>&1
  82. reg add "%app_regedit%\shell\1_pre" /v "Icon" /t REG_SZ /d "shell32.dll,-16749" /f >nul 2>&1
  83. reg add "%app_regedit%\shell\1_pre\command" /ve /t REG_SZ /d "wscript.exe ""%vbsPath%"" prev" /f >nul 2>&1
  84. reg add "%app_regedit%\shell\2_next" /v "MUIVerb" /t REG_SZ /d "下一张" /f >nul 2>&1
  85. reg add "%app_regedit%\shell\2_next" /v "Icon" /t REG_SZ /d "shell32.dll,-16750" /f >nul 2>&1
  86. reg add "%app_regedit%\shell\2_next\command" /ve /t REG_SZ /d "wscript.exe ""%vbsPath%"" next" /f >nul 2>&1
  87. reg add "%app_regedit%\shell\3_latest" /v "MUIVerb" /t REG_SZ /d "最新" /f >nul 2>&1
  88. reg add "%app_regedit%\shell\3_latest" /v "Icon" /t REG_SZ /d "imageres.dll,-5100" /f >nul 2>&1
  89. reg add "%app_regedit%\shell\3_latest\command" /ve /t REG_SZ /d "wscript.exe ""%vbsPath%"" latest" /f >nul 2>&1
  90. reg add "%app_regedit%\shell\4_random" /v "MUIVerb" /t REG_SZ /d "随机" /f >nul 2>&1
  91. reg add "%app_regedit%\shell\4_random" /v "Icon" /t REG_SZ /d "imageres.dll,-1401" /f >nul 2>&1
  92. reg add "%app_regedit%\shell\4_random\command" /ve /t REG_SZ /d "wscript.exe ""%vbsPath%"" rand" /f >nul 2>&1
  93. reg add "%app_regedit%\shell\5_autoChange" /v "MUIVerb" /t REG_SZ /d "自动更换" /f >nul 2>&1
  94. ::reg add "%app_regedit%\shell\5_autoChange" /v "Icon" /t REG_SZ /d "shell32.dll,-253" /f >nul 2>&1
  95. reg add "%app_regedit%\shell\5_autoChange\command" /ve /t REG_SZ /d "wscript.exe ""%vbsPath%"" toggle_auto_change" /f >nul 2>&1
  96. :: ----------------
  97. reg add "%app_regedit%\shell\6_0setting" /v CommandFlags /t REG_DWORD /d 0x00000008 /f >nul 2>&1
  98. reg add "%app_regedit%\shell\6_network" /v "MUIVerb" /t REG_SZ /d "联网壁纸" /f >nul 2>&1
  99. reg add "%app_regedit%\shell\6_network" /v "Icon" /t REG_SZ /d "imageres.dll,-1404" /f >nul 2>&1
  100. reg add "%app_regedit%\shell\6_network" /v "SubCommands" /t REG_SZ /d "" /f >nul 2>&1
  101. reg add "%app_regedit%\shell\6_network\shell\1_bingWallpaper" /v "MUIVerb" /t REG_SZ /d "下载必应壁纸" /f >nul 2>&1
  102. reg add "%app_regedit%\shell\6_network\shell\1_bingWallpaper" /v "Icon" /t REG_SZ /d "imageres.dll,-184" /f >nul 2>&1
  103. reg add "%app_regedit%\shell\6_network\shell\1_bingWallpaper\command" /ve /t REG_SZ /d "wscript.exe ""%vbsPath%"" load_bing_wallpaper" /f >nul 2>&1
  104. reg add "%app_regedit%\shell\6_network\shell\2_bingDayWallpaper" /v "MUIVerb" /t REG_SZ /d "必应每日一图" /f >nul 2>&1
  105. :: reg add "%app_regedit%\shell\6_network\shell\2_bingDayWallpaper" /v "Icon" /t REG_SZ /d "shell32.dll,-253" /f >nul 2>&1
  106. reg add "%app_regedit%\shell\6_network\shell\2_bingDayWallpaper\command" /ve /t REG_SZ /d "wscript.exe ""%vbsPath%"" day_bing_wallpaper" /f >nul 2>&1
  107. :: ----------------
  108. reg add "%app_regedit%\shell\7_0setting" /v CommandFlags /t REG_DWORD /d 0x00000008 /f >nul 2>&1
  109. reg add "%app_regedit%\shell\7_setting" /v "MUIVerb" /t REG_SZ /d "设置" /f >nul 2>&1
  110. reg add "%app_regedit%\shell\7_setting" /v "Icon" /t REG_SZ /d "shell32.dll,-16826" /f >nul 2>&1
  111. reg add "%app_regedit%\shell\7_setting" /v "SubCommands" /t REG_SZ /d "" /f >nul 2>&1
  112. reg add "%app_regedit%\shell\7_setting\shell\1_wallpaperPath" /v "MUIVerb" /t REG_SZ /d "设置壁纸目录" /f >nul 2>&1
  113. reg add "%app_regedit%\shell\7_setting\shell\1_wallpaperPath" /v "Icon" /t REG_SZ /d "shell32.dll,-46" /f >nul 2>&1
  114. reg add "%app_regedit%\shell\7_setting\shell\1_wallpaperPath\command" /ve /t REG_SZ /d "wscript.exe ""%vbsPath%"" set_wallpaperPath" /f >nul 2>&1
  115. reg add "%app_regedit%\shell\7_setting\shell\2_openWallpaperPath" /v "MUIVerb" /t REG_SZ /d "打开壁纸目录" /f >nul 2>&1
  116. reg add "%app_regedit%\shell\7_setting\shell\2_openWallpaperPath" /v "Icon" /t REG_SZ /d "shell32.dll,-37" /f >nul 2>&1
  117. reg add "%app_regedit%\shell\7_setting\shell\2_openWallpaperPath\command" /ve /t REG_SZ /d "wscript.exe ""%vbsPath%"" open_wallpaperPath" /f >nul 2>&1
  118. reg add "%app_regedit%\shell\7_setting\shell\3_openInstallDir" /v "MUIVerb" /t REG_SZ /d "打开应用目录" /f >nul 2>&1
  119. reg add "%app_regedit%\shell\7_setting\shell\3_openInstallDir" /v "Icon" /t REG_SZ /d "shell32.dll,-264" /f >nul 2>&1
  120. reg add "%app_regedit%\shell\7_setting\shell\3_openInstallDir\command" /ve /t REG_SZ /d "wscript.exe ""%vbsPath%"" open_installDir" /f >nul 2>&1
  121. if "%smw_log%"=="1" (
  122.         reg add "%app_regedit%\shell\7_setting\shell\4_cleanlog" /v "MUIVerb" /t REG_SZ /d "清理日志" /f >nul 2>&1
  123.         reg add "%app_regedit%\shell\7_setting\shell\4_cleanlog" /v "Icon" /t REG_SZ /d "shell32.dll,-261" /f >nul 2>&1
  124.         reg add "%app_regedit%\shell\7_setting\shell\4_cleanlog\command" /ve /t REG_SZ /d "cmd.exe /c del /F /Q "%installDir%\\log\\smw.log"" /f >nul 2>&1
  125. )
  126. reg add "%app_regedit%\shell\7_setting\shell\5_uninstall" /v "MUIVerb" /t REG_SZ /d "卸载" /f >nul 2>&1
  127. reg add "%app_regedit%\shell\7_setting\shell\5_uninstall" /v "Icon" /t REG_SZ /d "shell32.dll,-32" /f >nul 2>&1
  128. reg add "%app_regedit%\shell\7_setting\shell\5_uninstall\command" /ve /t REG_SZ /d "wscript.exe ""%vbsPath%"" uninstall" /f >nul 2>&1
  129. call :print_log "安装%appNameCN% end"
  130. echo.&echo.
  131. echo.&echo  安装成功,默认安装位置:%installDir%
  132. echo.&echo  请在桌面空白处右键%appNameCN%,设置壁纸目录后使用!
  133. echo.&echo  该文件已拷贝至安装目录下,因此不用刻意保留,除非你有别的用途。
  134. echo. & pause & exit /b
  135. :uninstall
  136. set "uninstall_script=%TEMP%\uninstall_script.bat"
  137. (
  138.         echo @echo off
  139.         echo cd /d "%%TEMP%%"
  140.         echo reg delete "%app_regedit%" /f ^>nul 2^>nul
  141.         echo rd /s /q "%installDir%" ^>nul 2^>nul
  142.         echo schtasks /delete /tn "%autoChangeTaskName%" /F ^>nul 2^>nul
  143.         echo schtasks /delete /tn "%dayBingWallpaperTaskName%" /F ^>nul 2^>nul
  144.         echo del /F /Q "%%~f0" ^>nul 2^>nul
  145. ) > "%uninstall_script%"
  146. start "" /B cmd /c call "%uninstall_script%" & exit
  147. :choose_wallpaper
  148. set "direction=%param[1]%"
  149. for %%A in ("%current_wallpaper%") do set "current_name=%%~nxA"
  150. set "prev=" & set "found=" & set "next=" & set /a count=0 & set "rand="
  151. for /f "delims=" %%F in ('dir /b /a:-d /o:-d "%smw_wallpaperPath%\*.bmp" "%smw_wallpaperPath%\*.jpg" "%smw_wallpaperPath%\*.jpeg" "%smw_wallpaperPath%\*.png" 2^>nul') do (
  152.         set /a count+=1
  153.         set /a r=%random% %% !count!
  154.         if !r! EQU 0 set "rand=%smw_wallpaperPath%\%%~F"
  155.         if not defined latest set "latest=%smw_wallpaperPath%\%%~F"
  156.         set "last_file=%smw_wallpaperPath%\%%~F"
  157.         if not defined found (
  158.                 if "%%F"=="%current_name%" (
  159.                         set "found=1"
  160.                 ) else set "prev=%smw_wallpaperPath%\%%~F"
  161.         ) else (
  162.                 if not defined next set "next=%smw_wallpaperPath%\%%~F"
  163.         )
  164. )
  165. if not defined found if defined latest set "prev=%latest%"
  166. if not defined next if defined latest set "next=%latest%"
  167. if not defined prev set "prev=%last_file%"
  168. if "%rand%" == "%current_wallpaper%" set "rand=%last_file%"
  169. if "%direction%"=="prev" set "selected_wallpaper=%prev%"
  170. if "%direction%"=="next" set "selected_wallpaper=%next%"
  171. if "%direction%"=="rand" set "selected_wallpaper=%rand%"
  172. if "%direction%"=="latest" set "selected_wallpaper=%latest%"
  173. if not defined selected_wallpaper exit /b
  174. call :set_wallpaper
  175. exit /b
  176. :toggle_auto_change
  177. :: 0关闭 1开启
  178. if "%smw_auto_change%"=="0" (
  179. for /f "usebackq delims=" %%i in (`
  180.         powershell -NoProfile -WindowStyle Hidden -Command ^
  181.                 "Add-Type -AssemblyName PresentationFramework, PresentationCore, WindowsBase;" ^
  182.                 "$window = New-Object System.Windows.Window;" ^
  183.                 "$window.Title = '%appNameCN%';" ^
  184.                 "$window.Width = 350; $window.Height = 180;" ^
  185.                 "$window.WindowStartupLocation = 'CenterScreen';" ^
  186.                 "$window.ResizeMode = 'NoResize';" ^
  187.                 "$stackPanel = New-Object System.Windows.Controls.StackPanel;" ^
  188.                 "$stackPanel.Margin = New-Object System.Windows.Thickness(15);" ^
  189.                 "$comboPanel = New-Object System.Windows.Controls.StackPanel;" ^
  190.                 "$comboPanel.Orientation = 'Horizontal';" ^
  191.                 "$comboPanel.HorizontalAlignment = 'Center';" ^
  192.                 "$comboPanel.Margin = '0,0,0,20';" ^
  193.                 "$label = New-Object System.Windows.Controls.Label;" ^
  194.                 "$label.Content = '更换频率:';" ^
  195.                 "$label.VerticalAlignment = 'Center';" ^
  196.                 "$label.Margin = '0,0,10,0';" ^
  197.                 "$comboBox = New-Object System.Windows.Controls.ComboBox;" ^
  198.                 "$comboBox.Width = 100; $comboBox.Height = 20;" ^
  199.                 "$options = [ordered]@{ ' 1 分钟'='00:01:00'; ' 5 分钟'='00:05:00'; '10 分钟'='00:10:00'; '15 分钟'='00:15:00'; " ^
  200.                                 "'30 分钟'='00:30:00';' 1 小时'='01:00:00'; ' 3 小时'='03:00:00'; ' 6 小时'='06:00:00'; '12 小时'='12:00:00' };" ^
  201.                 "$options.Keys | ForEach-Object { $comboBox.Items.Add($_) | Out-Null };" ^
  202.                 "$comboBox.SelectedIndex = 0;" ^
  203.                 "$comboPanel.Children.Add($label) | Out-Null;" ^
  204.                 "$comboPanel.Children.Add($comboBox) | Out-Null;" ^
  205.                 "$buttonPanel = New-Object System.Windows.Controls.StackPanel;" ^
  206.                 "$buttonPanel.Orientation = 'Horizontal';" ^
  207.                 "$buttonPanel.HorizontalAlignment = 'Center';" ^
  208.                 "$buttonPanel.Margin = '0,30,0,0';" ^
  209.                 "$okButton = New-Object System.Windows.Controls.Button;" ^
  210.                 "$okButton.Content = '确定'; $okButton.Width = 80; $okButton.Margin = '0,0,20,0';" ^
  211.                 "$okButton.Add_Click({ $window.Tag = 'OK'; $window.Close() });" ^
  212.                 "$cancelButton = New-Object System.Windows.Controls.Button;" ^
  213.                 "$cancelButton.Content = '取消'; $cancelButton.Width = 80;" ^
  214.                 "$cancelButton.Add_Click({ $window.Tag = 'Cancel'; $window.Close() });" ^
  215.                 "$buttonPanel.Children.Add($okButton) | Out-Null;" ^
  216.                 "$buttonPanel.Children.Add($cancelButton) | Out-Null;" ^
  217.                 "$stackPanel.Children.Add($comboPanel) | Out-Null;" ^
  218.                 "$stackPanel.Children.Add($buttonPanel) | Out-Null;" ^
  219.                 "$window.Content = $stackPanel;" ^
  220.                 "$window.ShowDialog() | Out-Null;" ^
  221.                 "if ($window.Tag -eq 'OK') { $sel = $comboBox.SelectedItem; Write-Output $options[$sel] } else { Write-Output 'CANCELLED' }"
  222.         `) do set "timeSpanStr=%%i"
  223.         if /i "!timeSpanStr!"=="CANCELLED" exit /b
  224.         ::添加任务计划
  225.         call :print_log "添加任务计划:%autoChangeTaskName%"
  226.         call :print_log "添加任务计划时间频率:!timeSpanStr!"
  227.         powershell -nologo -command ^
  228.                 "$parts = '!timeSpanStr!' -split ':';"^
  229.                 "$ts = New-TimeSpan -Hours $parts[0] -Minutes $parts[1] -Seconds $parts[2];"^
  230.                 "$now = Get-Date -Format 'HH:mm';" ^
  231.                 "$trigger = New-ScheduledTaskTrigger -Once -At $now -RepetitionInterval $ts;"^
  232.                 "$action = New-ScheduledTaskAction -Execute 'wscript.exe' -Argument '"%vbsPath%" next';"^
  233.                 "$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 0;"^
  234.                 "Register-ScheduledTask -TaskName '%autoChangeTaskName%' -Trigger $trigger -Action $action -Settings $settings -Force;"
  235.         reg add "%app_regedit%\shell\5_autoChange" /v "Icon" /t REG_SZ /d "shell32.dll,-253" /f >nul 2>&1
  236.         set "smw_auto_change=1"
  237.         call :show_message "已设置%autoChangeTaskName%"
  238. ) else (
  239.         call :print_log "取消任务计划: %autoChangeTaskName%"
  240.         schtasks /delete /tn "%autoChangeTaskName%" /F
  241.         reg delete "%app_regedit%\shell\5_autoChange" /v "Icon" /f >nul 2>&1
  242.         set "smw_auto_change=0"
  243.         call :show_message "已取消%autoChangeTaskName%"
  244. )
  245. call :print_log "设置smw_auto_change %smw_auto_change%"
  246. call :save_config
  247. exit /b
  248. :set_wallpaper
  249. call :print_log "设置壁纸: %selected_wallpaper%"
  250. if not exist "%selected_wallpaper%" exit /b
  251. powershell -Command "Add-Type -TypeDefinition 'using System.Runtime.InteropServices; public class Wallpaper { [DllImport("user32.dll", CharSet=CharSet.Auto)] public static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni); }'; [void][Wallpaper]::SystemParametersInfo(20, 0, '%selected_wallpaper%', 3)"
  252. exit /b
  253. :select_folder
  254. for /f "usebackq delims=" %%i in (
  255.         `powershell -noprofile -command "$shell=New-Object -ComObject Shell.Application; $folder=$shell.BrowseForFolder(0,'%~1',0,0); if($folder){$folder.Self.Path}"`
  256. ) do set "selectedFolder=%%i"
  257. exit /b
  258. :set_wallpaperPath
  259. call :select_folder "请选择壁纸文件夹"
  260. if not defined selectedFolder (
  261.         call :print_log "未输入路径,操作已取消。"
  262.         exit /b
  263. )
  264. set "smw_wallpaperPath=%selectedFolder%"
  265. call :print_log "已设置壁纸目录:%selectedFolder%"
  266. call :show_message "已设置壁纸目录:%selectedFolder%"
  267. call :save_config
  268. exit /b
  269. :open_wallpaperPath
  270. powershell -command "Invoke-Item -Path '%smw_wallpaperPath%'"
  271. exit /b
  272. :open_installDir
  273. powershell -command "Invoke-Item -Path '%installDir%'"
  274. exit /b
  275. :: 下载bing壁纸
  276. :load_bing_wallpaper
  277. if not exist "%smw_wallpaperPath%" mkdir "%smw_wallpaperPath%"
  278. set "baseUrl=https://www.bing.com"
  279. set /a bCounter=0
  280. for /L %%i in (0,1,1) do (
  281.         set /a index = %%i * 7
  282.         set /a num = %%i + 7
  283.         set "jsonUrl=!baseUrl!/HPImageArchive.aspx?format=js&idx=!index!&n=!num!&mkt=zh-CN&nc=1614319565639&pid=hp&FORM=BEHPTB&uhd=1&uhdwidth=3840&uhdheight=2160"
  284.         for /f "usebackq tokens=1,* delims=@" %%A in (`
  285.                 powershell -nologo -command ^
  286.                         "$ErrorActionPreference = 'Stop';" ^
  287.                         "try {" ^
  288.                         "  $ProgressPreference = 'SilentlyContinue';" ^
  289.                         "  $json = Invoke-RestMethod -Uri '!jsonUrl!' -UseBasicParsing;" ^
  290.                         "  if ($null -eq $json.images -or $json.images.Count -eq 0) { exit 1 }" ^
  291.                         "  $json.images | ForEach-Object { Write-Output ('!baseUrl!' + $_.url + '@' + $_.enddate + '_' + $_.title) }" ^
  292.                         "} catch { exit 1 }"
  293.         `) do (
  294.                 set /a bCounter+=1
  295.                 set "imageUrl[!bCounter!]=%%A"
  296.                 set "imageName[!bCounter!]=%%B"
  297.         )
  298. )
  299. call :print_log "获取Bing壁纸数量: %bCounter%"
  300. if %bCounter% EQU 0 call :show_message "无可用联网壁纸" & exit /b
  301. set /a downloadCounter=0
  302. for /L %%i in (!bCounter!,-1,1) do (
  303.         set "bingImagePath=%smw_wallpaperPath%\!imageName[%%i]!.jpg"
  304.         if not exist !bingImagePath! (
  305.                 call :print_log "下载地址:!imageUrl[%%i]!"
  306.                 call :print_log "下载文件:!imageName[%%i]!.jpg"
  307.                 call :print_log "本地地址:%smw_wallpaperPath%\!imageName[%%i]!.jpg"
  308.                 curl.exe --retry 2 --max-time 30 -so "!bingImagePath!" "!imageUrl[%%i]!"
  309.                 set "selected_wallpaper=!bingImagePath!"
  310.                 set /a downloadCounter+=1
  311.         )
  312. )
  313. if %downloadCounter% GTR 0 (
  314.         call :show_message "已成功下载 %downloadCounter% 张必应壁纸"
  315. ) else (
  316.         call :show_message "本地已更新,无需重复下载"
  317. )
  318. if defined selected_wallpaper call :set_wallpaper
  319. exit /b
  320. :day_bing_wallpaper
  321. :: 0关闭 1开启
  322. if "%smw_day_bing_wallpaper%"=="0" (
  323.         ::添加任务计划
  324.         call :print_log "添加任务计划:%dayBingWallpaperTaskName%"
  325.         powershell -nologo -command ^
  326.                 "$trigger1 = New-ScheduledTaskTrigger -Daily -At 00:00;"^
  327.                 "$trigger2 = New-ScheduledTaskTrigger -AtLogOn -User $env:USERNAME;"^
  328.                 "$trigger2.Delay = 'PT1M';"^
  329.                 "$action = New-ScheduledTaskAction -Execute "wscript.exe" -Argument '"%vbsPath%" load_bing_wallpaper task';"^
  330.                 "$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries;"^
  331.                 "Register-ScheduledTask -TaskName "%dayBingWallpaperTaskName%" -Trigger $trigger1, $trigger2 -Action $action -Settings $settings;"
  332.         reg add "%app_regedit%\shell\6_network\shell\2_bingDayWallpaper" /v "Icon" /t REG_SZ /d "shell32.dll,-253" /f >nul 2>&1
  333.         set "smw_day_bing_wallpaper=1"
  334.         call :show_message "已设置每天自动下载必应壁纸"
  335. ) else (
  336.         call :print_log "取消任务计划:%dayBingWallpaperTaskName%"
  337.         schtasks /delete /tn "%dayBingWallpaperTaskName%" /F
  338.         reg delete "%app_regedit%\shell\6_network\shell\2_bingDayWallpaper" /v "Icon" /f >nul 2>&1
  339.         set "smw_day_bing_wallpaper=0"
  340.         call :show_message "已取消每天自动下载必应壁纸"
  341. )
  342. call :print_log "设置smw_day_bing_wallpaper %smw_day_bing_wallpaper%"
  343. call :save_config
  344. exit /b
  345. :save_config
  346. (for %%p in (%requiredParams%) do echo %%p=!%%p!) > "%configFile%"
  347. exit /b
  348. :show_message
  349. :: 任务执行的不弹框
  350. if not "%param[2]%"=="task" (
  351.     start "" powershell -windowstyle hidden -command "Add-Type -AssemblyName PresentationFramework; [System.Windows.MessageBox]::Show('%~1', '%appNameCN%', 'OK', 'Information')"
  352. )
  353. exit /b
  354. :print_log
  355. if "%smw_log%"=="1" (
  356.         echo.[%date% %time%] %~1>> %installDir%\log\smw.log
  357. )
  358. exit /b
复制代码
鸣谢

特别感谢博客园提供文章发布平台~

来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
您需要登录后才可以回帖 登录 | 立即注册