electron / packager

Customize and package your Electron app with OS-specific bundles (.app, .exe, etc.) via JS or CLI
https://npm.im/@electron/packager
BSD 2-Clause "Simplified" License
126 stars 11 forks source link

--win32metadata.requested-execution-level=requireAdministrator Can't create shortcut desktop app when install app after build. #1560

Open PhiHoangNguyen13799 opened 10 months ago

PhiHoangNguyen13799 commented 10 months ago

STEP TO REPRODUCE

  1. Build by electron-packager with cmd --win32metadata.requested-execution-level=requireAdministrator Miniique "scripts": { "build-prod": "electron-packager src --platform=win32 --arch=x64 --icon=icon.ico Miniique prod && node build.js", "build-stag": "electron-packager src --platform=win32 --arch=x64 --icon=icon.ico Miniique stag && node build.js", "build-dev": "electron-packager src --platform=win32 --arch=x64 --icon=icon.ico --win32metadata.requested-execution-level=requireAdministrator Miniique dev && node build.js" }

    1. When install app After build
image

It will show popup to request admin permission from your computer.

  1. After choose yes for the request admin permission. App run, and all the feature work, but it can't create shortcut in desktop.

(May be admin don't have permission to create shortcut in desktop)

If i don't add --win32metadata.requested-execution-level=requireAdministrator . And do all the same step. App work perfectly. But some case we need to write or read file in computer. We need admin permission.

Code create shortcut may be helpful

const squirrelEvent = process.argv[1]; switch (squirrelEvent) { case '--squirrel-install': case '--squirrel-updated':

  // Install desktop and start menu shortcuts
  spawnUpdate(['--createShortcut', shortcutName]);

  setTimeout(application.quit, 1000);
  return true;

case '--squirrel-uninstall':
  // --squirrel-updated handlers

  // Remove desktop and start menu shortcuts
  spawnUpdate(['--removeShortcut', shortcutName]);

  setTimeout(application.quit, 1000);
  return true;

case '--squirrel-obsolete':
  // This is called on the outgoing version of your app before
  // we update to the new version - it's the opposite of
  // --squirrel-updated

  application.quit();
  return true;

} };

welcome[bot] commented 10 months ago

👋 Thanks for opening your first issue here! If you have a question about using Electron Packager, read the support docs. If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. Development and issue triage is community-driven, so please be patient and we will get back to you as soon as we can.

To help make it easier for us to investigate your issue, please follow the contributing guidelines.