Jump to content

Unable to change desktop wallpaper (Windows 7 Pro)


matty45
 Share

Recommended Posts

Hi, i have tried to use many scripts to change a pcs wallpaper but they dont work.

This script sets the wallpaper but does not refresh it.  Any idea what the problem is?

#include <SendMessage.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <Misc.au3>
#RequireAdmin

$UrlDownload = "http://examplesite.org/test.bmp" ;DL link
$Directory = "C:\test.bmp"      ;Name of your file

Local $download = InetGet($UrlDownload, $Directory,0,1) ; download in the background
Do
Sleep(100)
Until InetGetInfo($download, 2) ;Checks to see if $download is completed (param 2)
InetClose($download)
RunWait($Directory)  ;it will pause the script untill the process of the downloaded file is finished

RegWrite ("HKEY_CURRENT_USER\Control Panel\Desktop", "wallpaper", "REG_SZ", "C:\test.bmp" )

Dim $hWnd = WinGetHandle('[CLASS:Progman]')
_SendMessage($hWnd, $WM_COMMAND, 0x0001A220)

Thanks

Matthew

Edited by matty45
Link to comment
Share on other sites

It is because you are writing it to the registry. With this method you need to restart the explorer.exe process. Any script I have done where I am making changes to the theme like that, I always restart the computer.

There is another way to do it, but I did not spend enough time to make it be "nice." One is you save your image file to wherever. Then you make a new or modify an existing .theme file and put in the wallpaper path there. Then you load the theme. If you simply shellexecute the file, it will load everything in it, but it will open the Personalize window.

The other method is to use the API call that Windows normally uses to set the wallpaper, for example if you were to set something from a browser context menu. I never got this to work but I didn't spend enough time on it.

Link to comment
Share on other sites

Hi.

You can try to ProcessClose() all instances of explorer.exe, then start explorer.exe again.

Note:

The first instance of Explorer.exe is "the desktop". Maybe it's "re-reading" it's environment, when you restart it. (Pls. test yourself)

 

Note 2:

For Windows 7, there is a solution to plainly force "the desktop" to reload it's environment, including Env-Variables and all the registry keys like that one you are using. I used it few years ago, worked fine. Unfortunately I didn't note howto, and I cannot find the posting again describing how to do so (possibly some rundll32.exe <params>)

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

Hi.

Possibly this could do the trick :D

 

Nothing in WIndows should ever be that hard.

The following has always been the preferred method for refreshing the wallpapaer. Try it.

In PowerShell:

set-itemproperty HKCU:\'Control Panel\Desktop'  Wallpaper 'c:\windows\Coffee Bean.bmp'
RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters ,1 ,True

In batch.

reg add "HKCU\Control Panel\Desktop" /v WallPaper /d "c:\windows\Coffee Bean.bmp" /f
RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters ,1 ,True

 

or that one:

You could try broadcasting a WM_SETTINGCHANGE message. For example:

class Program
{
    [DllImport("user32.dll", SetLastError = true)]
    private static extern IntPtr SendMessageTimeout(IntPtr hWnd, int Msg, IntPtr wParam, string lParam, uint fuFlags, uint uTimeout, IntPtr lpdwResult);

    private static readonly IntPtr HWND_BROADCAST = new IntPtr(0xffff);
    private const int WM_SETTINGCHANGE = 0x1a;
    private const int SMTO_ABORTIFHUNG = 0x0002;

    static void Main(string[] args)
    {
        SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, IntPtr.Zero, null, SMTO_ABORTIFHUNG, 100, IntPtr.Zero);
    }
}

 

 

Regards, Rudi.

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

  • 3 weeks later...

Its ok, I managed to solve it in vbs

Here is the code if your curious:

If WScript.Arguments.Named.Exists("elevated") = False Then
  CreateObject("Shell.Application").ShellExecute "wscript.exe", """" & WScript.ScriptFullName & """ /elevated", "", "runas", 1
  WScript.Quit
End If
User = CreateObject("WScript.Shell").ExpandEnvironmentStrings("%UserProfile%")
dim Key, fso, Eater
Set Key = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set oSHApp = CreateObject("Shell.Application")
Set Eater = fso.GetFile(Wscript.ScriptFullName)

DownPic
DownChanger
DownBat
ChangeWall
CleanUp

Sub DownPic
dim xHttp, bStrm
Set xHttp = createobject("Microsoft.XMLHTTP")
Set bStrm = createobject("Adodb.Stream")
 xHttp.Open "GET", "http://whatever.com/test.bmp", False
 xHttp.Send

 with bStrm
 .type = 1
 .open
.write xHttp.responseBody
 .savetofile "C:\8ydfdsE.bmp", 2
End With
End Sub

Sub DownChanger
dim xHttp, bStrm
Set xHttp = createobject("Microsoft.XMLHTTP")
Set bStrm = createobject("Adodb.Stream")
 xHttp.Open "GET", "http://matthewsstuff.altervista.org/wallpaperchanger/WallpaperChanger.exe", False
 xHttp.Send

 with bStrm
 .type = 1
 .open
.write xHttp.responseBody
 .savetofile "C:\wpc.exe", 2
End With
End Sub

Sub DownBat
dim xHttp, bStrm
Set xHttp = createobject("Microsoft.XMLHTTP")
Set bStrm = createobject("Adodb.Stream")
 xHttp.Open "GET", "http://matthewsstuff.altervista.org/wallpaperchanger/wpc.bat", False
 xHttp.Send

 with bStrm
 .type = 1
 .open
.write xHttp.responseBody
 .savetofile "C:\wpce.bat", 2
End With
End Sub

Sub ChangeWall
Set rchange = CreateObject ("Wscript.Shell") 
Dim Silent
Silent = "cmd /c C:\wpce.bat"
rchange.Run Silent, 0, false
End Sub

Sub CleanUp
WScript.Sleep 5000
Dim deleter
Set deleter = CreateObject("Scripting.FileSystemObject")
deleter.DeleteFile "C:\8ydfdsE.bmp", True
deleter.DeleteFile "C:\wpce.bat", True
deleter.DeleteFile "C:\wpc.exe", True
End Sub

Thanks for the help

Edited by matty45
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...