I have a problem with changing wallpaper via code, i have below code as every SO/Codeproject threads talks about on changing wallpaper. (Have not tested on other Win OS so far)
const int SPI_SETDESKWALLPAPER = 20;
const int SPIF_UPDATEINIFILE = 0x01;
const int SPIF_SENDWININICHANGE = 0x02;
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern int SystemParametersInfo(
int uAction, int uParam, string lpvParam, int fuWinIni);
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, @"C:\Temp\100_5715.JPG.bmp",
SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
The actual problem i have here is that if i make the above code as windows service and install it as a “Local Service” or “Local System”, it wont work at all. But if i make the above code as a ConsoleApp, then things work.
I wonder whats the problem? Yes my user account has Admin rights. Also i have Windows 7 Ultimate here.
Thanks 🙂
Services run in their own session, called session 0 since Vista. It is isolated from the user session for security reasons, services run with a very privileged account. You are changing the desktop of that otherwise invisible session.
You can’t use a service.