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

Running as administrator disables other instances #162

Open
josago97 opened this issue Dec 13, 2023 · 3 comments
Open

Running as administrator disables other instances #162

josago97 opened this issue Dec 13, 2023 · 3 comments
Labels
bug Something isn't working help wanted Extra attention is needed Windows

Comments

@josago97
Copy link

If you run an executable as administrator and later open another instance of the same executable, that new instance does not work, the inputs, the buttons do, but text, number or selector inputs do not work.

@MikeYeager MikeYeager added bug Something isn't working help wanted Extra attention is needed Windows labels Dec 14, 2023
@MikeYeager
Copy link
Collaborator

@josago97 We are able to reproduce this, but we're stumped as to why it's occurring. For us, it only happens if we have an instance running "As Administrator", and then start one or more other instance normally. The normal instance(s) has the issue. Additional instances running "As Administrator" work fine. Once all "As Administrator" instances are shut down, all new normal instances work as expected. Any normal instances still open that had the issue, still do not work. This appears to be an issue with the WebView2 control as the native window still operates as expected. We cannot reproduce the issue with the full Edge web browser. Any help on this one is appreciated!

@markan-io
Copy link

It's an issue with User data folder being shared between elevated and non-elevated process. If you run both instances with different temporary files path, then it works fine. That said, creating new temp folder for each instance leaves behind a bunch of trash, and webview starts with a fresh profile on each run. Isn't ideal.

VSCode for example, won't allow to start non-elevated instance if an elevated on is already running.

@MikeYeager
Copy link
Collaborator

Adding some documentation notes for future reference:
https://learn.microsoft.com/en-us/microsoft-edge/webview2/concepts/user-data-folder?tabs=win32

#include <windows.h>
#include <iostream>

bool IsRunningAsAdmin()
{
    BOOL isElevated = FALSE;
    HANDLE hToken = NULL;

    if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
    {
        TOKEN_ELEVATION elevation;
        DWORD dwSize;

        if (GetTokenInformation(hToken, TokenElevation, &elevation, sizeof(elevation), &dwSize))
        {
            isElevated = elevation.TokenIsElevated;
        }

        CloseHandle(hToken);
    }

    return isElevated;
}

int main()
{
    if (IsRunningAsAdmin())
    {
        std::cout << "Running with elevated privileges (Administrator)." << std::endl;
    }
    else
    {
        std::cout << "Not running with elevated privileges." << std::endl;
    }

    return 0;
}

It is possible to detect running as an administrator and overriding the temp path based on that. For example, adding .admin to the folder name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed Windows
Projects
None yet
Development

No branches or pull requests

3 participants