2

This has been asked before here in a different form ( Powershell - Change windows 7 background to image off a website ) but I am still running into a bit of trouble here

I have a variable in windows 7 (PC): Set-Variable DEF_IMG -value 'C:\Windows\Web\Wallpaper\Windows\img0.jpg'

And I have tried a number of things:

set-ItemProperty -path "HKCU:Control Panel\Desktop" -name WallPaper -value $DEF_IMG
set-ItemProperty 'HKCU:\Software\Microsoft\Internet Explorer\Desktop\General' -name WallpaperSource -value $DEF_IMG
REG add 'HKCU\Control Panel\Desktop' /v Wallpaper /t REG_SZ /d $DEF_IMG /f
regedit /s $DEF_IMG

and at the end of course I always try

RUNDLL32.exe user32.dll, UpdatePerUserSystemParameters, 1, True

Once in a blue moon running some of those scripts seem to change the actual background, but most of the time the values in the registry change but the image stays the same. As for when it changes, there does not seem to be any rhyme or reason behind it. I think I am missing something important about how Windows handles its background image vs themes.. or something?

I am trying to do all of it directly in Powershell (no C code, no extra plug-ins or extensions, trying to maintain a clean system)

Community
  • 1
  • 1
Daniel Cazan
  • 323
  • 1
  • 4
  • 13
  • dupes http://stackoverflow.com/questions/9440135/powershell-script-from-shortcut-to-change-desktop – Andy Arismendi Apr 15 '13 at 22:42
  • Sorry, I had seen that one as well actually, but the accepted solution there was not Powershell, it looks like some version of C and requires PInvoke - which is perfectly fine, but not quite the scope I am shooting for. The more I played with it the more I am wondering if maybe the computer is just odd, if no one else is running into this with the above lines. – Daniel Cazan Apr 16 '13 at 05:09
  • It's PowerShell calling the Win32 API via custom object written in C#. You don't need anything special to run it, just PowerShell. The technique is known as platform invoking (pinvoke) and is the only reliable way I've seen to change the desktop wallpaper programmatically. – Andy Arismendi Apr 16 '13 at 05:11
  • That's what I was afraid of.. I will see if I can have permission to add a custom object into the project and then try that, if it is the only way - I was so sure there had to be a stable built in windows call, but is as it is. Thank you Andy! – Daniel Cazan Apr 16 '13 at 17:56

0 Answers0