Reputation: 2730
I have a C# background service. This service polls a webservice for updates. If the webservice returns an update, the C# service runs a powershell script and passes the url where the update is.
This powershell script then takes the url, downloads the update (a simple .zip file), extracts the contents of the update, and runs another powershell script that always comes with an update.
This all works perfectly, but some powershell commands don't do anything when executed this way. For example, I created an update with a jpg image, and let the powershell script that comes with the update set that image as desktop background. If I execute this update manually, it works and sets the new background. But if I let the C# service call the powershell script it doesn't set the background, even when I log out after it still doesn't set it.
Another command that doesn't seem to work is writing to the registry. I have the following code in an update:
New-Item -Path HKCU:\Software\ -Name bza -Value "Default Value" –Force
When I execute this it creates the key bza
in Software
. When the C# service calls the script nothing happens in the registry, even after logging out and back in.
I think there are two possible explanations for this. It can be insufficient rights, or it can be that a powershell script that runs from the background (without a window) can't do everything it would normally be able to do.
Does anyone have a solution for this?
P.S. The reason we don't let the C# service execute these tasks is that we want to be able to expand this update system in the future and this way we can just upload powershell scripts that can do pretty much anything.
P.P.S The devices this runs on are our own. We have every right to alter them in any way we want, regarding of what users want.
Upvotes: 1
Views: 709
Reputation: 9678
The most likely cause would be that the service runs as a different user or the system user. The desktop picture is set in HKEY_CURRENT_USER so it is important to run the powershell script in the correct user context.
Upvotes: 2