Set wallpaper and auto refresh desktop problem

Hi

I’m deploying a package via SCCM, which basically checks to see if it’s been X number of days since the last reboot. If that’s true, I need to set a custom wallpaper with a warning. That wallpaper should then revert to our original after e reboot (scheduled task).

But the script bit where the wallpaper and refresh part takes place, does not apply when deploynig the package via SCCM. It works if I execute the code in Powershell ISE, though. So is it something to do with in which context it’s run?

The snippet of code that doesn’t apply is:

param($path)
if(!$path)
{
$path = “c:<path to jpg locally on pc>”
}

$setwallpapersrc = @"
using System.Runtime.InteropServices;
public class wallpaper
{
public const int SetDesktopWallpaper = 20;
public const int UpdateIniFile = 0x01;
public const int SendWinIniChange = 0x02;
[DllImport(“user32.dll”, SetLastError = true, CharSet = CharSet.Auto)]
private static extern int SystemParametersInfo (int uAction, int uParam, string lpvParam, int fuWinIni);
public static void SetWallpaper ( string path )
{
SystemParametersInfo( SetDesktopWallpaper, 0, path, UpdateIniFile | SendWinIniChange );
}
}
"@
Add-Type -TypeDefinition $setwallpapersrc
[wallpaper]::SetWallpaper($path)

Whilst your approach is perfectly valid, you may want to consider an alternative we use.
Its sending out Toast notifications to our ‘restart pending’ collection.
Have a look at this:
toast notification

Thanks, I will look into that. :slight_smile:

A quick question… Is it possible to have both PendingRebootUptime and PendingRebootCheck active at the same time in the xml/script? It seems I get an error when I have both to True.

No. The code only allows one.