Share via

WinUI3 Webview2 is not working in non-admin mode

Vishal2 Bansal 345 Reputation points
2026-03-25T11:57:54.52+00:00

Hi

  1. In WPF .netframework based application , i use to create separate user data folders for different users and pass that to my webview2 environment while creating webview2 object. It works fine.
  2. But with WinUI3 , i am doing the same thing but my coreWebview2 is not initialized in case the app is running in non-admin mode.

I am getting error as System.Runtime.InteropServices.COMException (0x8007139F)

Pls help to debug why webview corewebview2 is not initializing in case of winui3 app for non-admin users?

For admin case it is working fine.

My webview2 edge browser version is latest 146.0.3856.72

Pls note my Webview user data folder has writable permission by non-admin user.

Windows development | WinUI
0 comments No comments

Answer accepted by question author
  1. Nancy Vo (WICLOUD CORPORATION) 2,805 Reputation points Microsoft External Staff Moderator
    2026-03-26T03:58:38.4333333+00:00

    Hi @Vishal2 Bansal ,

    Thanks for your question.

    In WinUI 3, WebView2 runs browser processes under the current user context, and it requires full access not only to the specified user data folder, but also the ability to create and manage its internal structure. Even if the folder appears writable, certain locations may still block non-admin processes due to Windows security restrictions.

    The error 0x8007139F typically indicates that WebView2 failed to initialize its runtime environment, which can happen when the user data folder is not fully accessible or is in an invalid state.

    You can refer to some of the solutions and example code below:

    • Use a per-user writable location such as LocalApplicationData:
    string baseDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
    string userDataFolder = Path.Combine(baseDataPath, "YourAppName", "UserData", currentUserId);  // currentUserId is whatever you use to separate users
    
    Directory.CreateDirectory(userDataFolder);
    
    
    var env = await CoreWebView2Environment.CreateAsync(
        browserExecutableFolder: null,
        userDataFolder: userDataFolder,
        options: null);
    
    await myWebView.EnsureCoreWebView2Async(env);
    
    • Add error catching so you can see the real message.
    try
    {
        var env = await CoreWebView2Environment.CreateAsync(...);
        await myWebView.EnsureCoreWebView2Async(env);
    }
    catch (Exception ex)
    {
        System.Diagnostics.Debug.WriteLine($"WebView2 failed: {ex.Message}");
        if (ex.InnerException != null)
            System.Diagnostics.Debug.WriteLine($"Inner: {ex.InnerException.Message}");
    }
    
    • If the folder was created by admin before, run the app once as admin, let it create the folder, then close it. After that, normal users should be able to use it.
    • Try removing the custom userDataFolder completely and let WinUI3 use its own safe default location. Only use custom if you really need separate folders per use.

    I hope this addresses your question. If this response was helpful, please consider following the guidance to provide feedback


1 additional answer

Sort by: Most helpful
  1. Q&A Assist
    2026-03-25T11:58:20.3+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    For non-admin users in a WinUI 3 app, CoreWebView2 typically fails to initialize when the user data folder (UDF) is not writable or cannot be created at the specified path. In WebView2, this produces errors such as E_ACCESSDENIED or related HRESULTs when the UDF is in a protected location.

    Key points from the platform behavior:

    • On desktop (.NET / Win32), a custom user data folder should be used in most cases instead of the default, and it must be in a location where the current user has write permissions.
    • If the UDF is under a protected area (for example, under Program Files or another location where standard users do not have write access), WebView2 cannot create or write to it and initialization fails.
    • Errors like Unable to create user data folder, Access Denied. or User data folder cannot be created because a file with the same name already exists. are typical when the UDF is misconfigured.

    To debug and fix the issue in the WinUI 3 scenario:

    1. Ensure the custom UDF path is per-user and writable
      • Use a per-user app data location (for example, under the same folder where other app data is stored for that user) rather than a machine-wide or protected folder.
      • Confirm that the non-admin user has full write permissions to that folder.
    2. Create the WebView2 environment with an explicit userDataFolder
      • Use CoreWebView2Environment.CreateAsync and pass a userDataFolder that points to the per-user writable directory:
         string userDataFolder = "C:\\MyAppUserDataFolderForThisUser"; // example; must be writable by the user
         var env = await CoreWebView2Environment.CreateAsync(
             browserExecutableFolder: null,
             userDataFolder: userDataFolder,
             options: new CoreWebView2EnvironmentOptions(null, language: null, additionalBrowserArguments: null));
         
         await webView.EnsureCoreWebView2Async(env, controllerOptions: null);
      
      This pattern is the same conceptually as in WPF/WinForms: the environment is created with a custom UDF and then passed into EnsureCoreWebView2Async.
    3. Handle initialization errors explicitly
      • Wrap the environment creation and EnsureCoreWebView2Async in try/catch and log the exception details, including any inner exceptions and message text. WebView2 surfaces specific error messages for UDF issues, such as:
        • User data folder cannot be created because a file with the same name already exists.
        • Unable to create user data folder, Access Denied.
      • These errors are generally fatal for that environment; handle them by notifying the user and closing or retrying with a different folder.
    4. Verify there is no conflicting file at the UDF path
      • Ensure the UDF path is a directory, not a file. If a file with the same name exists, initialization fails with the corresponding error.
    5. Avoid installer-protected locations
      • If the WinUI 3 app is installed under a location where the default UDF would end up in a protected path, always override it with a per-user data folder. Installer technologies often place apps under protected areas, which is why a custom UDF is recommended.

    Once the UDF is moved to a per-user, writable location and passed via CoreWebView2Environment.CreateAsync, CoreWebView2 should initialize correctly for non-admin users as it does for admin users.


    References:

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.