Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

Works in My Documents, not in Program Files

Post Reply
mddmx
Posts: 14
Joined: Fri Dec 13, 2019 2:42 pm

Works in My Documents, not in Program Files

Post by mddmx »

While I can get this to work well under my development folder (under my documents) it does not seem to want to work under PROGRAM FILES.
Upon initializing there is a popup error "Microsoft Edge can't read and write to it's data directory c:\program files(x86)\My Program\EBWebview

I have set the GlobalWebView2Loaders.UserDataFolder to a proper folder, but it seems to just get ignored.

Any idea?
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Works in My Documents, not in Program Files

Post by salvadordf »

Check that the Windows user executing the application has write privileges in the directory assigned to GlobalWebView2Loaders.UserDataFolder

A subdirectory of the user's AppData folder is a good place to store the cache.
mddmx
Posts: 14
Joined: Fri Dec 13, 2019 2:42 pm

Re: Works in My Documents, not in Program Files

Post by mddmx »

The popupbrowser demo application also fails with the same error when it's installed under Program Files and as you know due to that location, the user does not have the rights to store any data there. Even if I run it as administrator it still errors out. The error occurs on CREATE before we get to change the UserDataFolder

The issue seems "to me" that the function GetModulePath assumes that the dll is located in the application directory. If we had a property on GlobalWebView2Loader that allowed us to set a dll path then it we can just install the dll into the application data folder and all is good.
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Works in My Documents, not in Program Files

Post by salvadordf »

WebView2 requires a directory with write privileges for the user data.

The demos set GlobalWebView2Loader.UserDataFolder to a subdirectory where the EXE is located. If you try to move the EXE to any directory without write privileges they will give an error.

If you need to execute your application from a protected directory like "Program Files" then you need to set GlobalWebView2Loader.UserDataFolder to a writable directory and you need to set this property before the GlobalWebView2Loader.StartWebView2 call.

The demos create GlobalWebView2Loader in the initialization section of the main unit and the initialization section is executed even before the first code line of the DPR file and much before the TForm.OnCreate event.

You can move the code that creates GlobalWebView2Loader to another place but then you need to make sure the browsers are created after the GlobalWebView2Loader initialization.
Post Reply