0

I need to open it on startup to change the wallpaper at day n night

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

This is the vbs that will open batch files that will change the Reg

Batch file for day

@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

Batch file for night

    @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

but when i use the vbs it did not change the registry

Please Help

Thanks

Anuja Nimesh
  • 408
  • 3
  • 13

2 Answers2

0

Just create a single batch file, without the VBS and run it.

Note!! there are delays caused with rundll32.exe if being run after another, so if this runs continually to test, it will not update each time.

@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

keep in mind, enabledelayedexpansion is not really needed here.

Gerhard
  • 22,678
  • 7
  • 27
  • 43
0

I would do it like this, (especially because the output of %TIME% is machine dependent):

@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
Compo
  • 36,585
  • 5
  • 27
  • 39