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

requestedExecutionLevel not working on target Portable Build #7566

Closed
HyunhoCho opened this issue May 2, 2023 · 4 comments
Closed

requestedExecutionLevel not working on target Portable Build #7566

HyunhoCho opened this issue May 2, 2023 · 4 comments

Comments

@HyunhoCho
Copy link

HyunhoCho commented May 2, 2023

Version: ^23.6.0
Electron Version: ^19.0.0
Target: Portable

Hi, I am new to electron and electron-builder. I have this config (see below), and I am trying to make my application having requireAdministrator for requestedExecutionLevel. The build is successful, however, when I open my application, it doesn't ask/request to be run as administrator. Can someone help me on this? Thank you in advance.

I Think that when i tried double click my App,
Windows OS suggest Alert about usage of Administrator Auth.

    config:{
        asar: true,
        win: {

            target: [
                {
                target: 'portable',
                arch: [
                    'x64'
                    ]
                },
            ],
            icon: 'src/static/images/favicon_STg_icon.ico',             
            requestedExecutionLevel : 'requireAdministrator',
            },
        nsis: {
            oneClick: false,
            perMachine: true,
            installerIcon: 'src/static/images/favicon_STg_icon.ico',
            createDesktopShortcut: true,
            allowElevation: false,
        },
        directories: {
            buildResources: './resources/installer/',
            output: './dist/',
        },
        buildVersion: '20200524'

    }
}).then(function(value){
    console.log('result', value);
    
}).catch(function(error) {
    console.log('catch', error);
  }).finally(function() {
    if (typeof cbFunc === 'function') {
      cbFunc();
    }
});

}

@qazhub
Copy link

qazhub commented May 9, 2023

I've had the same issue with 23.3.3. The built exe file would unpack, but it does not ask for admin elevation, the app does not launch at all. If I go to the unpacked directory (inside Temp) manually, I can see the exe file has a shield icon on it, and launching it would correctly ask for admin elevation.

@qazhub
Copy link

qazhub commented May 11, 2023

It's an issue of the documentation. By reading throughout the source code, I found another option related the elevation of portable builds, see here and here.

So the correct configuration should be like this:

{
  // ...
  win: {
    target: [
      {
        target: "portable",
        arch: [ "x64" ]
      }
    ],
    artifactName: "xxxxx",
    requestedExecutionLevel: "requireAdministrator",  // This is mentioned in the doc
  },
  portable: {
    requestExecutionLevel: "admin", // However this is not
  }
  // ...
}

You need to put requestExecutionLevel under portable key too, and it has different option values as well.

@qazhub
Copy link

qazhub commented May 15, 2023

The win.requestedExecutionLevel key controls your main program (the entrance .exe file), and the portable.requestExecutionLevel controls the final portable .exe file.
When launching a portable app, the portable .exe runs first, it extracts all the files - includes the main .exe file - to a temporary directory; it would then run the main .exe file.

So the win.requestedExecutionLevel is not necessary. If the portable .exe required admin elevation upon launching, the main program (your app process) would inherit the privilege as well. So setting portable.requestExecutionLevel is enough.

@HyunhoCho
Copy link
Author

Wow Thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants