matty45

Unable to change desktop wallpaper (Windows 7 Pro)

5 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
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.

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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!

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


Link to post
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

  • Similar Content

    • steveeye
      By steveeye
      hey, can anybody enlighten on lesser known Windows hacks or uses ?
    • afallenhope
      By afallenhope
      Hello all! 
      I am having a bit of trouble and was wondering if anyone may have a workaround for my issue. I made a script that would automatically install a piece of software each night on a Windows 7 Box. Now I have been instructed to do the same with a Windows 10 box since the application is now being tested on Windows 10. 
      The way I did the win7 installation was that I made a script and then made an executable that I call with a batch file along with the Installer. So the process is 
      AutoitMainFile calls batch file, batch file opens Installer, and the automatedinstaller.exe  The automatedinstlaller waits 10-20 seconds to make sure the Installer has been fully loaded.
      When I try to do the same both get loaded but the automatedinstallation.exe does not send commands to the installer. The code does work and nothing from the program we are wanting to install has changed as our Windows 7 runs every night no problem. 
       
      Do I need to make a new automatedinstall script for windows 10? 
      Any advice is appreciated 
      Thanks,
      Richard
    • ur
      By ur
      I have enabled admin sharing in the remote machine so that I can copy files to the remote machine use PSEXEC to execute our application remotely.
        Now, if the machine is poweredoff we need to poweriton. So I checked whether the remote machine, it is of both VirtualBox or VMWare one. For VirtualBox or VMware, I have found command line utities to poweron.   But to autologon by skipping the login screen.Can anyone suggest how to do the same.If it is a physical machine, then there is no need to poweron but autologon is required.   I am trying for windows machines.Win 7 at present.   For VirtualBox I checked below link with help og guestadditions but not working. http://www.virtualbox.org/manual/ch09.html#autologon   The below procedure will save the password in that machine and it will logon automatically.   http://www.howtogeek.com/112919/how-to-make-your-windows-8-computer-logon-automatically/   But it will give access to everyne.But my opinion is he should access only if have credentias.I mean through any commandline from another machine he should trigger logon also by passing credentials.     Similarly this also   http://www.cnet.com/how-to/automatically-log-in-to-your-windows-10-pc/   http://superuser.com/questions/28647/how-do-i-enable-automatic-logon-in-windows-7-when-im-on-a-domain   http://pcsupport.about.com/od/windows7/ht/auto-logon-windows-7.htm   http://www.computerperformance.co.uk/windows7/windows7_auto_logon.htm   https://technet.microsoft.com/en-us/magazine/ee872306.aspx   Please guide me how to proceed.
    • cramaboule
      By cramaboule
      Autoit Airliners.net wallpaper changer Works from XP to W10
    • AJB
      By AJB
      Hello,
      I've been using autoit for about a year now and overall it's been great despite my limited understanding of all of its features. I have several scripts that run on virtual machines that have been running smoothly for several months without any issues. Recently, I had to create new virtual machines and migrate my scripts over and now I am getting errors that I can't seem to repeat, but seem to happen at least once a day with all of my executables that were flawless before.
      The error that I keep getting is:
      Autoit Error
      Line [this number varies per script] (File "[path to my executable]"); Error: variable must be of type object.
      I  never received this error before until I moved everything to the new VMs, and when I rerun my scripts after clearing the error everything seems to work and run fine until hours later or sometimes the next day. I am assuming that that the root cause may be in some kind of settings on the VM itself since it is happening nearly across the board, but I have no idea where to even look. These are running on Windows 7, which is what they were running on before I had any errors.
      The only consistent include used in these scripts is  IE.au3
      Has anyone run into a similar problem or can maybe point me in the right direction. I am at the point of pulling hair out trying to resolve this. I have even rewritten and re-compiled the scripts to see if somehow the executables got corrupted, but that didn't help.
      Thank you.