Error WBEM_E_INITIALIZATION_FAILURE from ExecMethod

I am trying to create a shadow copy of the C drive using wmivss. When I use the command line with wmic shadowcopy call create Volume='c:', it successfully creates the shadow copy and returns the following value:

Executing (Win32_ShadowCopy)->create()
Method execution successful.
Out Parameters:
instance of __PARAMETERS
{
        ReturnValue = 0;
        ShadowID = "{85CF0935-84D8-46A4-98DB-43753CA3AD46}";
};

However, when I try to achieve this using C++ code, I encounter an error during the execution of ExecMethod which states ExecMethod failed: WBEM_E_INITIALIZATION_FAILURE(80041014). I am not sure what went wrong in my implementation. I have tried starting my Volume Shadow Copy service, but it didn’t help. Here is my code.

#include <iostream>
#include <comdef.h>
#include <Wbemidl.h>
#include <windows.h>

#pragma comment(lib, "wbemuuid.lib")

void Cleanup(IWbemServices* pSvc, IWbemLocator* pLoc) {
    if (pSvc) {
        pSvc->Release();
    }
    if (pLoc) {
        pLoc->Release();
    }
    CoUninitialize();
}

HRESULT CreateShadowCopy(IWbemServices* pSvc, BSTR* pShadowID) {
    HRESULT hres;
    IWbemClassObject* pClass = nullptr;
    IWbemClassObject* pInParamsDefinition = nullptr;
    IWbemClassObject* pOutParams = nullptr;
    IWbemClassObject* pClassInstance = nullptr;

    // Get the class object for Win32_ShadowCopy
    hres = pSvc->GetObject(L"Win32_ShadowCopy", 0, nullptr, &pClass, nullptr);
    if (FAILED(hres)) {
        std::wcerr << L"GetObject failed: " << std::hex << hres << std::endl;
        return hres;
    }

    // Get the method's input parameters
    hres = pClass->GetMethod(L"Create", 0, &pInParamsDefinition, nullptr);
    if (FAILED(hres)) {
        std::wcerr << L"GetMethod failed: " << std::hex << hres << std::endl;
        pClass->Release();
        return hres;
    }

    // Create an instance of the input parameters class
    hres = pInParamsDefinition->SpawnInstance(0, &pClassInstance);
    if (FAILED(hres)) {
        std::wcerr << L"SpawnInstance failed: " << std::hex << hres << std::endl;
        pInParamsDefinition->Release();
        pClass->Release();
        return hres;
    }

    // Set the input parameters
    VARIANT vtVolume;
    VariantInit(&vtVolume);
    vtVolume.vt = VT_BSTR;
    vtVolume.bstrVal = SysAllocString(L"C:\");

    hres = pClassInstance->Put(L"Volume", 0, &vtVolume, 0);
    VariantClear(&vtVolume);

    if (FAILED(hres)) {
        std::wcerr << L"Put failed: " << std::hex << hres << std::endl;
        pClassInstance->Release();
        pInParamsDefinition->Release();
        pClass->Release();
        return hres;
    }

    // Execute the method
    hres = pSvc->ExecMethod(L"Win32_ShadowCopy", L"Create", 0, nullptr, pClassInstance, &pOutParams, nullptr);
    if (FAILED(hres)) {
        std::wcerr << L"ExecMethod failed: " << std::hex << hres << std::endl;
        pClassInstance->Release();
        pInParamsDefinition->Release();
        pClass->Release();
        return hres;
    }

    // Get the output parameters
    VARIANT vtShadowID;
    hres = pOutParams->Get(L"ShadowID", 0, &vtShadowID, nullptr, nullptr);
    if (FAILED(hres)) {
        std::wcerr << L"Get ShadowID failed: " << std::hex << hres << std::endl;
        pOutParams->Release();
        pClassInstance->Release();
        pInParamsDefinition->Release();
        pClass->Release();
        return hres;
    }

    *pShadowID = SysAllocString(vtShadowID.bstrVal);
    VariantClear(&vtShadowID);

    pOutParams->Release();
    pClassInstance->Release();
    pInParamsDefinition->Release();
    pClass->Release();

    return S_OK;
}

int wmain() {
    HRESULT hres;
    IWbemLocator* pLoc = nullptr;
    IWbemServices* pSvc = nullptr;
    BSTR shadowID = nullptr;

    // Step 1: Initialize COM.
    hres = CoInitializeEx(0, COINIT_MULTITHREADED);
    if (FAILED(hres)) {
        std::wcerr << L"CoInitializeEx failed: " << std::hex << hres << std::endl;
        return 1;
    }

    // Step 2: Set general COM security levels.
    hres = CoInitializeSecurity(
        nullptr,
        -1,                          // COM authentication
        nullptr,                    // Authentication services
        nullptr,                    // Reserved
        RPC_C_AUTHN_LEVEL_DEFAULT,  // Default authentication
        RPC_C_IMP_LEVEL_IMPERSONATE,// Default Impersonation
        nullptr,                    // Authentication info
        EOAC_NONE,                  // Additional capabilities
        nullptr                     // Reserved
    );

    if (FAILED(hres)) {
        std::wcerr << L"CoInitializeSecurity failed: " << std::hex << hres << std::endl;
        CoUninitialize();
        return 1;
    }

    // Step 3: Obtain the initial locator to WMI.
    hres = CoCreateInstance(
        CLSID_WbemLocator,
        0,
        CLSCTX_INPROC_SERVER,
        IID_IWbemLocator,
        (LPVOID*)&pLoc);

    if (FAILED(hres)) {
        std::wcerr << L"CoCreateInstance failed: " << std::hex << hres << std::endl;
        CoUninitialize();
        return 1;
    }

    // Step 4: Connect to WMI through the IWbemLocator::ConnectServer method.
    hres = pLoc->ConnectServer(
        _bstr_t(L"ROOT\CIMV2"),
        nullptr,
        nullptr,
        0,
        NULL,
        0,
        0,
        &pSvc);

    if (FAILED(hres)) {
        std::wcerr << L"ConnectServer failed: " << std::hex << hres << std::endl;
        pLoc->Release();
        CoUninitialize();
        return 1;
    }

    // Step 5: Set security levels on the proxy.
    hres = CoSetProxyBlanket(
        pSvc,
        RPC_C_AUTHN_WINNT,
        RPC_C_AUTHZ_NONE,
        nullptr,
        RPC_C_AUTHN_LEVEL_CALL,
        RPC_C_IMP_LEVEL_IMPERSONATE,
        nullptr,
        EOAC_NONE);

    if (FAILED(hres)) {
        std::wcerr << L"CoSetProxyBlanket failed: " << std::hex << hres << std::endl;
        Cleanup(pSvc, pLoc);
        return 1;
    }

    // Step 6: Create a shadow copy.
    hres = CreateShadowCopy(pSvc, &shadowID);
    if (FAILED(hres)) {
        std::wcerr << L"CreateShadowCopy failed: " << std::hex << hres << std::endl;
        Cleanup(pSvc, pLoc);
        return 1;
    }

    // Step 7: Print the shadow copy ID.
    std::wcout << L"Shadow Copy ID: " << shadowID << std::endl;

    // Step 8: Cleanup.
    Cleanup(pSvc, pLoc);
    return 0;
}


I also tried using CreateProcess to create a process to execute wmic shadowcopy call create Volume='c:'. It produced the same error:

Executing (Win32_ShadowCopy)->create()
ERROR:
Description = Initialization failure

I have no idea why this is happening.

New contributor

K.Aguilar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

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