无需附加应用程序即可安排 Windows XP 墙纸更改

无需附加应用程序即可安排 Windows XP 墙纸更改

理想情况下,我希望能够通过批处理文件或 VB 脚本来执行此操作,这样我就可以安排它在一天中的不同时间运行(晚上使用深色壁纸,白天使用浅色壁纸)。

我知道很多应用程序可以做到这一点,但我更喜欢只让必要的应用程序在后台运行。

答案1

您可以将计划任务与我刚刚破解的 VBScript 一起使用(例如,使用多个壁纸并每隔几分钟切换一次):

Randomize
Set obshell = WScript.CreateObject("Wscript.Shell")
num = Int( ( 100 - 1 + 1 ) * Rnd + 1 )
CurrentDir = "C:\Wallpapers\day\"
wallpaper = CurrentDir & "Wallpaper" & num & ".bmp"
obshell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper",wallpaper
obshell.Run "%windir%\System32\RUNDLL32.EXE user32.dll,
UpdatePerUserSystemParameters",1,False
Set obshell = Nothing

笔记:壁纸必须是位图。如果您想避免使用更多脚本定期检查系统时间,您可以使用相同的脚本来检查白天和夜晚,只需创建一个单独的计划任务并在所需的时间以所需的间隔运行它即可。创建 2 个文件夹,一个用于白天壁纸,一个用于夜晚壁纸,在每个文件夹中放入脚本的副本。您需要将100第 3 行更改为每个文件夹中的壁纸数量,然后将其重命名为Wallpaper1, Wallpaper2, etc以使此脚本正常工作(或修改脚本中的名称)。还要修改CurrentDir每个的值。

如果您只想使用 2 张壁纸(将其设置为每 59 分钟左右运行一次以确保您不会错过一个小时):

Set obshell = WScript.CreateObject("Wscript.Shell")
CurrentHour = Hour(Now)
If CurrentHour = 8 Then
    wallpaper = "C:\Wallpapers\day.bmp"
ElseIf CurrentHour = 20 Then
    wallpaper = "C:\Wallpapers\night.bmp"
Else
    WScript.Quit(0)
End If
obshell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper",wallpaper
obshell.Run "%windir%\System32\RUNDLL32.EXE user32.dll,
UpdatePerUserSystemParameters",1,False
Set obshell = Nothing

答案2

编辑:约翰的回答向您展示了完整的脚本。我给他 +1。这篇文章将成为您可能想要查看的另一个选项。

我对批处理命令有点生疏,所以我将给你重点介绍一下:

%TIME:~0,2%- 将返回 TIME 环境变量中的当前小时数

像这样:

IF %TIME:~0,2% == 19 CALL do_Night_Wallpaper.reg
IF %TIME:~0,2% == 07 CALL do_Day_Wallpaper.reg

将脚本放入任务计划程序并设置为每 1 小时运行一次就足够了。当然,您可能希望根据时区舒适度调整小时数。同时,IF 语句的编写方式是它们不会不必要地调用 reg 文件。但这意味着您必须将任务计划程序设置为至少每小时运行一次。

至于 reg 文件本身,这些是您所需要的设置:

  • HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System\Wallpaper
  • HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System\WallpaperStyle

第一个参数获取壁纸图像的完整路径。第二个参数是整数 0 = 居中,1 = 平铺,2 = 拉伸。

答案3

这是一个“随时可用”的小型 VBS 程序:它收集了所有这些命令(使用“Randomize”VBS 命令在目录中选择随机图片文件 + 使用“UpdatePerUserSystemParameters”刷新 Windows 壁纸 + 更新 Windows“WallpaperStyle”注册表)。

并且它可以处理.JPG图片文件(不仅仅是.BMP文件),非常方便......

VB 脚本源代码描述如下http://sites.google.com/site/sharerandomwallpapers/ 谢谢。

答案4

我只是尝试对 John 的脚本进行一些小的修改。我尝试让脚本能够根据一天中的时间每分钟更换一次壁纸。例如,从 5.00 到 8.59,它会更换几张带有早晨主题的壁纸;从 9.00 到 13.59,它会更换几张带有中午主题的壁纸;等等。此脚本中的每个主题包含 4 张 BMP 图像。由于脚本中包含五个主题(早晨、中午、下午、傍晚和夜晚),因此此脚本需要 20 张图像才能运行。

'creating procedure that changes wallpaper every minute
Sub ChangeWallpaperPerMinute ()
    Set obshell = WScript.CreateObject("Wscript.Shell")
    CurrentHour = Hour(Now)
    'determining the number of images for every time of the day-based theme (set the 'maximum' value according to the number of images for every theme)
    maximum=4
    minimum=1
    'randomizing the images to be changed
    Randomize
    num = Int((maximum-minimum+1)*Rnd+minimum)
    If CurrentHour >= 5 And CurrentHour <= 8 Then
        wallpaper = "morning" & num & ".bmp"
    ElseIf CurrentHour >= 9 And CurrentHour <= 13 Then
        wallpaper = "midday" & num & ".bmp"
    ElseIf CurrentHour >= 14 And CurrentHour <= 16 Then
        wallpaper = "afternoon" & num & ".bmp"
    ElseIf CurrentHour >= 17 And CurrentHour <= 20 Then
        wallpaper = "evening" & num & ".bmp"
    ElseIf CurrentHour >= 21 And CurrentHour <= 23 Then
        wallpaper = "night" & num & ".bmp"
    ElseIf CurrentHour >= 0 And CurrentHour <= 4 Then
        wallpaper = "night" & num & ".bmp"
    Else
        WScript.Quit(0)
    End If
    obshell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper",wallpaper
    obshell.Run "%windir%\System32\RUNDLL32.EXE user32.dll, UpdatePerUserSystemParameters",1,False
    Set obshell = Nothing
End Sub
'end of procedure creation'
'calling procedure to initiate script's action
ChangeWallpaperPerMinute
'repeating the calling of procedure
do
    WScript.sleep(60 * 1000)
    '60 * 1000 means sixty seconds. If the shifting of wallpapers is expected to occur once every ten seconds, change to 10 * 1000
    'calling procedure
    ChangeWallpaperPerMinute
Loop

要使此脚本可运行,除了脚本文件本身之外,还需要 20 张 BMP 图像。其中四张图像必须按照指定的命名法命名;例如,morning1.bmp、morning2.bmp、morning3.bmp 和 morning4.bmp。4 张中午图像、4 张下午图像、4 张傍晚图像和 4 张夜间图像的命名也适用相同的命名法。将 VBS 文件与这 20 张图像文件放在一个文件夹中。由于此脚本会按指定的时间间隔重复调用其过程,因此当您使用计划任务时,请确保仅在系统登录时激活此脚本。要停用此脚本,只需使用任务管理器终止 wscript.exe 即可。

相关内容