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