Skip to content

Set-DesktopWallpaper : Error HRESULT E_FAIL has been returned from a call to a COM component. #4

@robpomeroy

Description

@robpomeroy

Cześć!

Ref: PowerBGInfo issue #18.

Invoking Set-DesktopWallpaper -Index 0 -WallpaperPath C:\BGInfo\FooBarBackground.jpg on a Windows 11 24H2 (26100.3775) computer, elevated, generates the following error, if I have previously connected via RDP:

Set-DesktopWallpaper : Error HRESULT E_FAIL has been returned from a call to a COM component.
At line:1 char:1
+ Set-DesktopWallpaper -Index 0 -WallpaperPath C:\BGInfo\FooBarBackgrou ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Set-DesktopWallpaper], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,DesktopManager.PowerShell.CmdletSetDesktopWallpaper

Note that the following works on the same machine whether or not I've used RDP (don't know if it's of any help though):

Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;

public class Wallpaper {
    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    public static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);
}
"@

[Wallpaper]::SystemParametersInfo(20, 0, "C:\BGInfo\FooBarBackground.jpg", 3)

I see the same error, calling Get-DesktopWallpaper, with no parameters:

Get-DesktopWallpaper : Error HRESULT E_FAIL has been returned from a call to a COM component.
At line:1 char:1
+ Get-DesktopWallpaper
+ ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-DesktopWallpaper], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,DesktopManager.PowerShell.CmdletGetDesktopWallpaper

Steps to reproduce:

  • Boot machine
  • Log in via RDP
  • Disconnect from RDP without logging off
  • Connect locally as the same user (i.e. retaining the previous login session)
  • Run Get-DesktopWallpaper in PowerShell prompt

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions