It’s me, the scripting disaster again!
Perhaps someone can help me out with the following problem.
I’ve got this script, with a function which enables changing the current desktop wallpaper on the fly.
The Set-Wallpaper function (not created by myself) uses some embedded C# programming. More info about the function can be found here:
When I load the script in ISE and run it, it changes the wallpaper instantly.
The next thing I want for this, is to schedule it and run it invisible at the startup of my PC.
Now there are two options for scheduling a Powershell script that apparently make a world of difference.
- Run only when a user is logged on
- Run whether user is logged on or not
When I use the option 1. the script runs, changes the wallpaper, but unfortunately it shows an interactive script window flashing by.
However option 2. really is invisible, yet it doesn’t seem to change the wallpaper value for unknown reasons to me.
I tried building some troubleshooting log into the script, to pinpoint where it fails doing what it should:
"====================" |Out-File d:\test.txt "Randomised Wallpaper:" |Out-File d:\test.txt -Append ($WallPaper).FullName |Out-File d:\test.txt -Append "====================" |Out-File d:\test.txt -Append "Create dummy reg value:" |Out-File d:\test.txt -Append Set-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name Test -Value test "====================" |Out-File d:\test.txt -Append "Current user:" |Out-File d:\test.txt -Append [Environment]::UserName |Out-File d:\test.txt -Append "====================" |Out-File d:\test.txt -Append Set-Wallpaper -Path $WallPaper.FullName "====================" |Out-File d:\test.txt -Append "Registry value:" |Out-File d:\test.txt -Append Get-ItemProperty -Path 'HKCU:\Control Panel\Desktop\' -Name Wallpaper |Out-File d:\test.txt -Append "====================" |Out-File d:\test.txt -Append
When I open the log.txt, I can see the following checks
- It generates a random wallpaper
- Current user is me, which is correct
- It generates a dummy registry value, so permissions seem to be correct
- Set-Wallpaper does not give feedback
- Registry value remains unchanged
Why is the output different, when changing the “user logged on/not”-setting of the scheduled task? And why do my checks all give a positive result, except when executing the function inside the script?
If anyone got a clue about this one, please let me know!