Is it possible to get the user data folder without creating an instance of the WebView2 browser control?

48 views Asked by At

This is how WebView2 sample lets us get the user data folder:

auto environment7 = m_webViewEnvironment.try_query<ICoreWebView2Environment7>();
CHECK_FEATURE_RETURN(environment7);
wil::unique_cotaskmem_string userDataFolder;
environment7->get_UserDataFolder(&userDataFolder);

But, is it possible to get the user data folder without creating an instance of the browser control?

I know you can do this with the SDK / Runtime values:

std::wstring CWebBrowser::GetRuntimeVersion()
{
    wil::unique_cotaskmem_string runtimeVersion;
    GetAvailableCoreWebView2BrowserVersionString(nullptr, &runtimeVersion);
    return runtimeVersion.get();
}


std::wstring CWebBrowser::GetSdkBuild()
{
    auto options = Microsoft::WRL::Make<CoreWebView2EnvironmentOptions>();
    wil::unique_cotaskmem_string targetVersion;
    CHECK_FAILURE(options->get_TargetCompatibleBrowserVersion(&targetVersion));

    // The full version string A.B.C.D
    const wchar_t* targetVersionMajorAndRest = targetVersion.get();
    // Should now be .B.C.D
    const wchar_t* targetVersionMinorAndRest = wcschr(targetVersionMajorAndRest, L'.');
    CHECK_FAILURE((targetVersionMinorAndRest != nullptr && *targetVersionMinorAndRest == L'.') ? S_OK : E_UNEXPECTED);

    // Should now be .C.D
    const wchar_t* targetVersionBuildAndRest = wcschr(targetVersionMinorAndRest + 1, L'.');
    CHECK_FAILURE((targetVersionBuildAndRest != nullptr && *targetVersionBuildAndRest == L'.') ? S_OK : E_UNEXPECTED);

    // Return + 1 to skip the first . so just C.D
    return targetVersionBuildAndRest + 1;
}

I would also like to get the runtime path without creating a browser instance (if possible).

0

There are 0 answers