Command-line app to set the desktop wallpaper

Working on Windows, I find myself installing Windows a lot.

I find that I like to change a lot of the settings that Windows offers to non-default values.  (That is, I'm picky.)

I have a script which automates some of these things, which I add to now and again.  Some of the bits of the script are straightforward, but once in a while the tweak itself is of interest.

One of the things I love about my work setup is the many large monitors.  So, one of the things I like to change is the desktop wallpaper image.

Changing the desktop wallpaper required some code, which makes it "of interest."  Here's the code.

// main.cpp

#include <windows.h>
#include <winuser.h>
#include <stdio.h>

int _cdecl wmain(int argc, LPCWSTR argv[]) {
    if (1 != argc - 1) {
        wprintf(L"expected a single argument, not %d\n", argc);
        return -__LINE__;
    if (!SystemParametersInfo(
    )) {
        DWORD dwErr = GetLastError();
        wprintf(L"SystemParametersInfo(...) failed with error %d\n", dwErr);
        return -__LINE__;
    wprintf(L"Setting the desktop wallpaper to %s succeeded.\n", argv[1]);   
    return 0;


Binaries attached.

Warning: if you pass a relative path to this tool, it won't qualify it for you, and the SystemParametersInfo call won't either - so the wallpaper you want won't be set, though all the calls will succeed.  Make sure to specify a fully-qualified path.

EDIT September 22 2015: removed source and binaries as this is obsoleted by

Comments (0)

Skip to main content