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.
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:
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!
Don is right HKCU is not there until some one is logged in I have done some remote registry stuff using the user SID but if the user was not logged in and I used HKCU it will return my admin info from the registry rather then the user.
And why does this line succeeds in adding a value to my HKCU path:
# Set-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name Test -Value test
Both commands in the same script, give me the proper behaviour.
Does the plot thickens?
Also, on a sidenote:
Even though I’ve selected option 2. Run whether user is logged on or not, the scheduled task still is only triggered to run at log on.
Does it show your user account or your admin account you are using to run the task? Try this set up the task as a different user I bet it will attempt to set the keys as that person. What is happening is the task is logging in as you to run the script. Like my example above when I used the SID to retrieve remote registry values if the user was logged off.
this line might help just change the User ID to the one you are trying to update
$SID = Get-WmiObject win32_useraccount -Filter “name = ‘User ID’” | Select SID
I just want this to work for my own (admin) account. I do not intend to use this remote or for other users. The thing that keeps bothering me, is that I can modify the HKCU-hive in the same script, but the Set-Wallpaper won’t work using the same scheduled task options.
My end-goal here, really is simply changing the wallpaper at startup without showing a Powershell window flashing by. I know…Windows has this option in the GUI. But I have a startup script that does a lot more with my wallpapers, allowing me to enjoy season themes without fiddling within the GUI.
The rundll32 part, should update the user-profile, thus modifying the wallpaper visibly on the fly. Drawback is, that this doesn’t work 5 out of 10 times.
The Set-Wallpaper function, really does some magic with the C# programming in there. I’m just a nitpicker who wants it to run on boot, fully hidden.
I was assuming wrongly that “WindowStyle Hidden” did not work. When you test-run a scheduled task from the Windows GUI, it apparently ignores the “WindowStyle” parameter and still shows a Powershell box popping up. However when testing by logging into Windows and allowing the script to run, the popup remains invisible.