我需要在启动时打开它以在第n天晚上更改壁纸
Dim objShell
str1 = "C:\Users\AnB\Desktop\Texts\Projects\Project WallTime\Day.bat"
str2 = "C:\Users\AnB\Desktop\Texts\Projects\Project WallTime\Night.bat"
Set objShell = Wscript.CreateObject("WScript.Shell")
if hour(time) < 17 then
objShell.Run str1
if hour(time) > 16 then
objShell.Run str2
end if
end if
这是将打开将更改Reg
的批处理文件的vbs当天的批处理文件
@echo off
reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v Wallpaper /t REG_SZ /d "C:\Users\AnB\Desktop\Texts\Projects\Project WallTime\Day and Night\Day.png" /f
RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters
晚上的批处理文件
@echo off
reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v Wallpaper /t REG_SZ /d "C:\Users\AnB\Desktop\Texts\Projects\Project WallTime\Day and Night\Night.png" /f
RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters
但是当我使用vbs时它没有更改注册表
请帮助
由于
答案 0 :(得分:0)
只需创建一个没有VBS的批处理文件并运行它。
请注意! rundll32.exe如果在另一个之后运行会导致延迟,所以如果连续运行测试,则每次都不会更新。
@echo off
setlocal enabledelayedexpansion
set "Wtime=!time:~0,2!"
if "!Wtime!" leq "17" reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v Wallpaper /t REG_SZ /d "C:\Users\AnB\Desktop\Texts\Projects\Project WallTime\Day and Night\Day.png" /f & goto done
if "!Wtime!" geq "17" reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v Wallpaper /t REG_SZ /d "D:\C:\Users\AnB\Desktop\Texts\Projects\Project WallTime\Day and Night\Night.png" /f & goto done
:done
timeout /t 5 >nul
start "" /b RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters
endlocal
请注意,此处并不需要enabledelayedexpansion
。
答案 1 :(得分:0)
我会这样做,(特别是因为%TIME%
的输出取决于机器):
@Echo Off
Set "locn=%UserProfile%\Desktop\Texts\Projects\Project WallTime"
Set "rstr=Reg Add "HKCU\Control Panel\Desktop" /V Wallpaper /D "
Set "str1=%locn%\Day.bat"
Set "str2=%locn%\Night.bat"
Set /A "now=10%TIME:~,2%" 2>Nul
If %now:~-2% Lss 17 (%rstr% "%str1%" /F >Nul
) Else %rstr% "%str2%" /F >Nul
RunDll32 User32.dll,UpdatePerUserSystemParameters >Nul