How to programmatically rename a virtual desktop?

I have been able to create desktops, get their name, switch, etc, but when I try to modify its name I’m getting an exception, compilable example code:

// desktop.h
#pragma once
#include <Windows.h>
#include <iostream>
#include <objectarray.h>
#include <atlbase.h>
#include <winstring.h>
#pragma comment(lib, "WindowsApp.lib")

const CLSID CLSID_ImmersiveShell                = { 0xC2F03A33, 0x21F5, 0x47FA, 0xB4, 0xBB, 0x15, 0x63, 0x62, 0xA2, 0xF2, 0x39 };
const CLSID CLSID_VirtualDesktopManagerInternal = { 0xC5E0CDCA, 0x7B6E, 0x41B2, 0x9F, 0xC4, 0xD9, 0x39, 0x75, 0xCC, 0x46, 0x7B };

MIDL_INTERFACE("372E1D3B-38D3-42E4-A15B-8AB2B178F513")

IApplicationView : public IUnknown
{
public:
};

MIDL_INTERFACE("FF72FFDD-BE7E-43FC-9C03-AD81681E88E4")
IVirtualDesktop : public IUnknown
{
public:
    virtual HRESULT STDMETHODCALLTYPE IsViewVisible(IApplicationView *pView, int *pfVisible) = 0;
    virtual HRESULT STDMETHODCALLTYPE GetID(GUID *pGuid) = 0;
};

MIDL_INTERFACE("31EBDE3F-6EC3-4CBD-B9FB-0EF6D09B41F4")
IVirtualDesktop2: public IVirtualDesktop
{
public:
    virtual HRESULT STDMETHODCALLTYPE GetName(_Out_ HSTRING* pStr) = 0;
};

const IID UUID_IVirtualDesktopManagerInternal_14393 { 0xf31574d6, 0xb682, 0x4cdc, 0xbd, 0x56, 0x18, 0x27, 0x86, 0x0a, 0xbe, 0xc6 };

enum AdjacentDesktopDirection: int
{

    AD_LEFT = 3,
    AD_RIGHT = 4,

};

class IVirtualDesktopManagerInternal : public IUnknown
{
public:
    virtual HRESULT __stdcall GetCount(int* pCount) = 0;
    virtual HRESULT __stdcall MoveViewToDesktop(/*IApplicationView*/ IUnknown* pView, IVirtualDesktop* pDesktop) = 0;
    virtual HRESULT __stdcall CanViewMoveDesktops(/*IApplicationView*/ IUnknown* pView, BOOL* bCanMove) = 0;
    virtual HRESULT __stdcall GetCurrentDesktop(IVirtualDesktop** ppDesktop) = 0;
    virtual HRESULT __stdcall GetDesktops(IObjectArray** ppArray) = 0;
    virtual HRESULT __stdcall GetAdjacentDesktop(IVirtualDesktop* pDesktopOrigin, AdjacentDesktopDirection nDirection, IVirtualDesktop** ppDesktop) = 0;
    virtual HRESULT __stdcall SwitchDesktop(IVirtualDesktop* pDesktop) = 0;
    virtual HRESULT __stdcall CreateDesktopW(IVirtualDesktop** ppDesktop) = 0;
    virtual HRESULT __stdcall RemoveDesktop(IVirtualDesktop* pRemoveDesktop, IVirtualDesktop* pFallbackDesktop) = 0;
    virtual HRESULT __stdcall FindDesktop(GUID* desktopId, IVirtualDesktop** ppDesktop) = 0;
    virtual HRESULT __stdcall SetDesktopName(IVirtualDesktop* pDesktop, HSTRING pName) = 0;

};

MIDL_INTERFACE("0F3A72B0-4566-487E-9A33-4ED302F6D6CE")
IVirtualDesktopManagerInternal2 : public IVirtualDesktopManagerInternal

{
public:
    virtual HRESULT __stdcall GetDesktopSwitchIncludeExcludeViews(IVirtualDesktop* pDesktop, IObjectArray** ppLeftDesktops, IObjectArray** ppRightDesktops) = 0;
    virtual HRESULT STDMETHODCALLTYPE SetDesktopName(_In_ IVirtualDesktop* p0, _In_ HSTRING name) = 0;

};

#include "desktop.h"

int main(int argc, char* argv[])
{
    HRESULT hr = ::CoInitialize(NULL);
    if (FAILED(hr))
    {

        std::cerr << "CoInitialize failed: " << std::hex << hr << std::endl;
        return FALSE;
    }

    IServiceProvider* pServiceProvider = nullptr;
    hr = ::CoCreateInstance(CLSID_ImmersiveShell, NULL, CLSCTX_LOCAL_SERVER, __uuidof(IServiceProvider), (PVOID*)&pServiceProvider);

    if (FAILED(hr))
    {

        std::cerr << "CoCreateInstance failed: " << std::hex << hr << std::endl;
        return FALSE;

    }

    //CComPtr<IVirtualDesktopManagerInternal> pDesktopManagerInternal = nullptr;
    CComPtr<IVirtualDesktopManagerInternal2> pDesktopManagerInternal = nullptr;
    hr = pServiceProvider->QueryService(CLSID_VirtualDesktopManagerInternal, UUID_IVirtualDesktopManagerInternal_14393, (void**)&pDesktopManagerInternal);

    if (FAILED(hr))
    {
        std::cerr << "QueryService(DesktopManagerInternal) failed: " << std::hex << hr << std::endl;
        pServiceProvider->Release();
        pServiceProvider = nullptr;
        return FALSE;
    }

    IVirtualDesktop* desktop = nullptr;
    hr = pDesktopManagerInternal->CreateDesktopW(&desktop);
    if (FAILED(hr))
        return 0;

    GUID id;
    hr = desktop->GetID(&id);
    if (FAILED(hr))
        return 0;

    HSTRING hString;

    LPCWSTR name = L"test123";
    WindowsCreateString(name, static_cast<UINT32>(wcslen(name)), &hString);
    //hr = static_cast<IVirtualDesktopManagerInternal2*>(pDesktopManagerInternal.p)->SetDesktopName(desktop, hString);
    hr = pDesktopManagerInternal->SetDesktopName(desktop, hString); // EXCEPTION
    return 0;

}

I’m aware that the ids changes between versions, atm i’m testing on WIN10 22H2 19045

To be more precise I’m getting an exception at this line:

hr = pDesktopManagerInternal->SetDesktopName(desktop, hString);

I have found these two repositories that uses the SetDesktopName:

RMVirtualDesktop

VirtualDesktopAccessor

The first does basically the same thing, the second is on rust, i have no experience with rust but im reading it, he’s calling SetDesktopName with IVirtualDesktop and not the IVirtualDesktop2, i also tried it but its also causing an exception.

Trying to figure out what’s wrong.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật