Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebView can't run as administrator #13

Open
PoulBak opened this issue Dec 12, 2018 · 8 comments
Open

WebView can't run as administrator #13

PoulBak opened this issue Dec 12, 2018 · 8 comments
Labels

Comments

@PoulBak
Copy link

@PoulBak PoulBak commented Dec 12, 2018

I'm submitting a...

Bug report (I searched for similar issues and did not find one)

Current behavior

If you try to your app as adminstrator (elevated), the app will not show, no errors or messages, it just doesn't show.

The reason this became an issue, was that I primarily develop websites, and to debug the local IIS, Visual Studio must run as admin, so I have changed the VS shortcut to require that. Unfornately this Means, that any app launched will also run as admin.

The proplem is that it's impossible to debug, when nothing is shown.

Expected behavior

The app should run (Edge can run as admin). If that isn't possible, I suggest, you check at startup, whether it runs as admin and then throw an exception: "WebView can't run as administrator".

That will save hours of frustrating debugging for many people,

Minimal reproduction of the problem with instructions

Run Visual Studio as admin, now launch an app with WebView.

Environment

Nuget Package(s):  Microsoft Toolkit Windows Forms WebView

Package Version(s): 5.01

Windows 10 Build Number:
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [x ] October 2018 Update (17763)
- [ ] Insider Build (build number: )

App min and target version:
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [x ] October 2018 Update (17763)
- [ ] Insider Build (xxxxx)

Device form factor:
- [x ] Desktop
- [ ] Mobile
- [ ] Xbox
- [ ] Surface Hub
- [ ] IoT

Visual Studio 
- [x ] 2017 (version: 15.9.4)
- [ ] 2017 Preview (version: )

@keiserS

This comment has been minimized.

Copy link

@keiserS keiserS commented Dec 16, 2018

I'm have the same issue with latest Win 10 updates, with VS2017 (latest).
Telling user he can't run as admin is not acceptable imho! It would be better to figure out what is the real cause of this and repair it, isn't it?

VS running in normal mode, starts debugging of the app without the problem, VS running in elevated mode ("Run as Administrator") give that error, and unfortunately I need elevated mode since have self hosted WebApi app (which will not run in normal mode) and win forms App using WebView (not working in normal mode?!?!).

So is there any news about this and how to overcome and resolve this? and what is the real cause of exception when VS/app is being run in elevated mode?

Exception being raised in InitializeComponent method is:
**The remote procedure call failed. (Exception from HRESULT: 0x800706BE)**

Can someone get insight how to overcome this? and what is the real reason.. here is stack trace:

at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT.WebViewControlProcess.<CreateWebViewControlHostAsync>d__16.MoveNext() in D:\a\1\s\WebView.Shared\Interop\WinRT\WebViewControlProcess.cs:line 95
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Toolkit.Forms.UI.Controls.WebViewControlProcessExtensions.CreateWebViewControlHost(WebViewControlProcess process, IntPtr hostWindowHandle, Rectangle bounds) in D:\a\1\s\Microsoft.Toolkit.Forms.UI.Controls.WebView\WebViewControlProcessExtensions.cs:line 178
   at Microsoft.Toolkit.Forms.UI.Controls.WebView.Initialize() in D:\a\1\s\Microsoft.Toolkit.Forms.UI.Controls.WebView\WebView.Init.cs:line 129
   at Microsoft.Toolkit.Forms.UI.Controls.WebView.System.ComponentModel.ISupportInitialize.EndInit() in D:\a\1\s\Microsoft.Toolkit.Forms.UI.Controls.WebView\WebView.Init.cs:line 67

@michael-hawker

This comment has been minimized.

Copy link
Member

@michael-hawker michael-hawker commented Mar 11, 2019

@joshholmes any info you can provide on this?

@NikasZalias

This comment has been minimized.

Copy link

@NikasZalias NikasZalias commented Apr 30, 2019

Is there any new info about this?

2 similar comments
@NikasZalias

This comment has been minimized.

Copy link

@NikasZalias NikasZalias commented May 24, 2019

Is there any new info about this?

@NikasZalias

This comment has been minimized.

Copy link

@NikasZalias NikasZalias commented Jul 5, 2019

Is there any new info about this?

@verelpode

This comment has been minimized.

Copy link

@verelpode verelpode commented Aug 10, 2019

I can also confirm that when I use the "Run as administrator" command to run a test WPF app that uses WebView, the WebView doesn't work. I don't see an error/exception, rather the WebView just remains blank.
(Nuget package version 6.0.0-preview7.1 running in Windows 10 version 1903 build 18362.267)

I'm just making a wild guess here, but is it possible that this admin bug is related to issue #165 (WPF WebView crashes when "explorer.exe" is not running) ? Maybe Windows.Web.UI.Interop.WebViewControlProcess launches the "WWAHost.exe" process in a manner equivalent to System.Diagnostics.ProcessStartInfo.UseShellExecute = true.

If that's what it does, then I think UseShellExecute = true is unsupported when the app is elevated/admin (if I remember correctly). Thus if WebViewControlProcess is modified to launch "WWAHost.exe" directly instead of launching via the shell/explorer, then maybe 2 bugs will be solved at the same time:

  1. Inability to run as admin/elevated.
  2. Inability to run when "explorer.exe" is not running.

Or maybe they are totally separate issues. I don't know.

@verelpode

This comment has been minimized.

Copy link

@verelpode verelpode commented Aug 12, 2019

I investigated further and noticed that the WWAHost.exe instance isn't running at all, whenever the WPF app (with WebView) is running as admin. I suggest that the solution might be to make Windows.Web.UI.Interop.WebViewControlProcess execute the Win32 GetCurrentProcessToken function followed by launching WWAHost.exe via either the CreateProcessWithTokenW function or the CreateProcessAsUserW function, in order to grant the new WWAHost instance the same level of access (admin access) as the app using WebView.

HOWEVER, the above idea may be rejected because of the security implications. Perhaps it's a bad idea to allow the web engine to process webpages while running as elevated admin. So, to work around this, I can't really say because the full source code is unavailable, but I guess maybe consider using Impersonation Tokens after launching WWAHost using the elevated token, but do this while keeping in mind that impersonation doesn't really work in the manner that people expect it to. Anyway, if possible, when creating the WebView's HWND, use the elevated/admin access, but when processing webpages, use a lower level of access.

In addition to invoking GetCurrentProcessToken, I also suggest invoking the GetThreadDesktop function in order to help solve the bug described in #166.

@Que8549

This comment has been minimized.

Copy link

@Que8549 Que8549 commented Jan 24, 2020

Any updates on this? This is still an issue in Microsoft.Toolkit.Forms.UI.Controls.WebView v6.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.