Skip to content

Commit

Permalink
docs: troubleshooting tips for cross-account admin perms and "Microso…
Browse files Browse the repository at this point in the history
…ft Edge can't read or write to its data directory" error

related:
- #2920 
- https://discord.com/channels/1042734330029547630/1154062298776862750
  • Loading branch information
AlbinoDrought authored Sep 21, 2023
1 parent e951926 commit 4c44b6d
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion website/docs/guides/troubleshooting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,61 @@ you can make the webview background transparent using the following config:
})
```

## I get a "Microsoft Edge can't read or write to its data directory" error when running my program as admin on Windows

You set your program to require admin permissions and it worked great! Unfortunately, some users are seeing a "Microsoft Edge can't read or write to its data directory" error when running it.

When a Windows machine has two local accounts:

- Alice, an admin
- Bob, a regular user

Bob sees a UAC prompt when running your program. Bob enters Alice's admin credentials into this prompt. The app launches with admin permissions under Alice's account.

Wails instructs WebView2 to store user data at the specified `WebviewUserDataPath`. It defaults to `%APPDATA%\[BinaryName.exe]`.

Because the application is running under Alice's account, `%APPDATA%\[BinaryName.exe]` resolves to `C:\Users\Alice\AppData\Roaming\[BinaryName.exe]`.

WebView2 [creates some child processes under Bob's logged-in account instead of Alice's admin account](https://github.com/MicrosoftEdge/WebView2Feedback/issues/932#issue-807464179). Since Bob cannot access `C:\Users\Alice\AppData\Roaming\[BinaryName.exe]`, the "Microsoft Edge can't read or write to its data directory" error is shown.

Possible solution #1:

Refactor your application to work without constant admin permissions. If you just need to perform a small set of admin tasks (such as running an updater), you can run your application with the minimum permissions and then use the `runas` command to run these tasks with admin permissions as needed:

```go
//go:build windows

package sample

import (
"golang.org/x/sys/windows"
"syscall"
)

// Calling RunAs("C:\path\to\my\updater.exe") shows Bob a UAC prompt. Bob enters Alice's admin credentials. The updater launches with admin permissions under Alice's account.
func RunAs(path string) error {
verbPtr, _ := syscall.UTF16PtrFromString("runas")
exePtr, _ := syscall.UTF16PtrFromString(path)
cwdPtr, _ := syscall.UTF16PtrFromString("")
argPtr, _ := syscall.UTF16PtrFromString("")

var showCmd int32 = 1 //SW_NORMAL

err := windows.ShellExecute(0, verbPtr, exePtr, argPtr, cwdPtr, showCmd)
if err != nil {
return err
}
return nil
}
```

Possible solution #2: change `WebviewUserDataPath` to a path writeable by both Alice and Bob.

Possible future solution #3: [run WebView2 using an in-memory mode if implemented](https://github.com/MicrosoftEdge/WebView2Feedback/issues/3637#issuecomment-1728300982).

## WebView2 installation succeeded, but the wails doctor command shows that it is not installed

If you have installed WebView2, but the `wails doctor` command shows that it is not installed, it is likely that the
WebView2 runtime installed was for a different architecture. You can download the correct runtime from [here](https://developer.microsoft.com/en-us/microsoft-edge/webview2/).

Source: https://github.com/wailsapp/wails/issues/2917
Source: https://github.com/wailsapp/wails/issues/2917

0 comments on commit 4c44b6d

Please sign in to comment.