0

I have some trouble with a PowerShell and Batch file. When I run a batch file in which a Powershell script is called, it runs normally. After a logoff and logon it´s as if nothing happened.

This is the batch file (SetWallpaper.bat):

@ECHO OFF
PowerShell.exe -NoProfile -Command "& {Start-Process PowerShell.exe -ArgumentList '-ExecutionPolicy Bypass -File ""%~dpn0.ps1""' -Verb RunAs}"
PAUSE

And here is my Powershell code (SetWallpaper.ps1):

Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value "<root>\Users\temp\Tree_Updown.jpg"
 rundll32.exe user32.dll, UpdatePerUserSystemParameters

As I said, it works, but after a logoff and on, the wallpaper is the default Windows picture.

The curiosity is, that when I launch just the Powershell code alone, without a batch, it works perfect.

I searched the web for some other alternatives, like launching the file via VBS, and it didn´t work.

VBS-code(LaunchSetWallpaper.vbs):

command = "powershell.exe -nologo -command <root>\Users\temp\SetWallpaper.ps1"
set shell = CreateObject("WScript.Shell")
shell.Run command,0

for some reason unknown, it doesn't do anything.

At this point, I don´t know what else to do. Hope someone can give me some advice.

Thanks.

Martin Leiva

meatspace
  • 859
  • 16
  • 25
Emal011
  • 11
  • 5
  • 3
    Are you changing `` when you run your code? Also you batch call looks redundant. You are calling PowerShell to call powershell to run a file. – Matt Jan 26 '15 at 15:55
  • 2
    And I think there is no PowerShell script necessary at all for your task. __reg.exe add__ can be also used to set the value for desktop wallpaper image. – Mofi Jan 26 '15 at 17:05
  • Why are you using "-NoProfile" ? It tells the powershell to not use the CurrentUsers Profile but the Registry you update is part of the users profile... – Syberdoor Jan 27 '15 at 08:00
  • @Mofi, I need Administrator access, that´s why I use Powershell code. At the beginnign I was using just a batch code: reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /V Wallpaper /T REG_SZ /D %APPDATA%\Microsoft\Windows\Themes\F11_IT_in_water_flow-wide_blau.jpg – Emal011 Jan 27 '15 at 08:28
  • @Matt, yeah, it is just for this example that I wrote – Emal011 Jan 27 '15 at 08:36
  • @Syberdoor, Well, as I said, it was an example from the internet, now that you describe the use of it, it really makes sense. I try it and show what happens.. – Emal011 Jan 27 '15 at 08:36
  • Questions seeking debugging help must include the desired behavior and of course the code which fails. As it turned out the posted code has not much to do with what the questioner really wants to do as otherwise administrator privileges and a PowerShell script would not be needed at all. So this question cannot be answered without knowing the real task and real code. – Mofi May 24 '15 at 17:49
  • if you put 20 times: "rundll32.exe user32.dll, UpdatePerUserSystemParameters" it works but it's not a great solution... – Nuno Luz Jun 28 '17 at 14:35

0 Answers0