-4

When I use a VBS script to change my wallpaper, I have to log off for changes to take effect. How can I make it so I don't have to log off once I run my script?

I am running Windows 7 and am running code which will take a given path file, such as a.jpg or a.bmp, and replace the file at the location:

C:\Users\Brad\AppData\Roaming\Microsoft\Windows\Themes\TranscodedWallpaper.jpg

I have listed the code for a VBS file that I found and it is supposed to refresh my active desktop. It flashes like the script works, however it does not update my wallpaper:

' Create explorer command file to toggle desktop window
Set oFSO = CreateObject("Scripting.FileSystemObject")
sSCFFile= oFSO.BuildPath(oFSO.GetSpecialFolder(2), oFSO.GetTempName &".scf")
With oFSO.CreateTextFile(sSCFFile, True)
.WriteLine("[Shell]")
.WriteLine("Command=2")
.WriteLine("[Taskbar]")
.WriteLine("Command=ToggleDesktop")
.Close
End With

' Toggle desktop and send F5 (refresh)
With CreateObject("WScript.Shell")
.Run """" & sSCFFile & """"
WScript.Sleep 100
.Sendkeys "{F5}"
End With
' Delete explorer command file
oFSO.DeleteFile sSCFFile
honk
  • 9,137
  • 11
  • 75
  • 83
Brad
  • 359
  • 5
  • 21
  • Way i see it you have 2 options. Use a 3rd Party utility like [SetWallpaper.exe](http://www.thoughtasylum.com/blog/2010/6/2/set-windows-wallpaper-from-the-command-line.html) or you can work magic with sendkeys like [this](http://social.technet.microsoft.com/Forums/scriptcenter/en-US/833eede7-ec49-4a09-b3ab-f2a8a0fde947/set-as-desktop-background-from-vbs?forum=ITCG) – Matt Aug 24 '14 at 23:14

2 Answers2

1

The settings are stored in memory. Changing the registry key changes nothing.

The way programs do it is to use SystemParametersInfo

SystemParametersInfo

Retrieves or sets the value of one of the system-wide parameters. This function can also update the user profile while setting a parameter.

BOOL SystemParametersInfo(
  UINT uiAction,
  UINT uiParam,
  PVOID pvParam,
  UINT fWinIni
);

SPI_SETDESKWALLPAPER

Sets the desktop wallpaper. The value of the pvParam parameter determines the new wallpaper. To specify a wallpaper bitmap, set pvParam to point to a null-terminated string containing the name of a bitmap file. Setting pvParam to "" removes the wallpaper. Setting pvParam to SETWALLPAPER_DEFAULT or NULL reverts to the default wallpaper.

VB.Net is installed all computers. Use that instead.

Noodles
  • 1,981
  • 1
  • 11
  • 4
0

I did a little searching and found a block of code for a .bat file that looks like this:

>      @echo off
>      taskkill /f /IM explorer.exe
>      Start explorer.exe
>      @pause

That resolves my issue since the background is loaded when explorer.exe starts up.

Brad
  • 359
  • 5
  • 21