简体   繁体   English

电子,电子生成器,nsis,卸载时删除 SchTasks

[英]Electron, electron-builder, nsis, remove SchTasks at uninstall

I made an app that is running with Admin Privileges.我制作了一个以管理员权限运行的应用程序。 To run the app at windows startup I made an SchTasks, but at uninstall I want to remove it.为了在 Windows 启动时运行该应用程序,我创建了一个 SchTasks,但在卸载时我想将其删除。 The closest I could get is:我能得到的最接近的是:

;script used to remove the auto launch scheduled task

!macro customUnInstall
  ExpandEnvStrings $0 %COMSPEC%
  ExecWait `"$0" /c "SchTasks /Delete /TN task_name /F & pause"`
!macroend

But it returns ERROR: Access is denied.但它返回ERROR: Access is denied. . . This is because the uninstall doesn't have admin priv.这是因为卸载没有管理员权限。 What should I do, should I try to make the uninstall to be executed with admin priv?我该怎么办,我应该尝试使用 admin priv 执行卸载吗? Or there is another way to remove the task?或者有另一种方法来删除任务?

Another option in my mind is to make the task to delete it self if the executable is not in path.我认为的另一个选择是,如果可执行文件不在路径中,则让任务自行删除。

The electron package.json I am using:我正在使用的电子 package.json:

"win": {
  "target": [
    "nsis"
  ],
  "requestedExecutionLevel": "requireAdministrator"
},
"nsis": {
  "include": "installer/windows/uninstall.nsh",
  "allowElevation": true,
  "deleteAppDataOnUninstall": true
},

我对 Electron-builder 一无所知,但我知道如果安装程序脚本具有RequestExecutionLevel Admin那么卸载程序也会在 Vista+ 上请求提升。

Here is my solution, in nsh file.这是我的解决方案,在 nsh 文件中。

!macro customHeader
   RequestExecutionLevel admin
!macroend

!macro customUnInstall
${ifNot} ${isUpdated}
    ; remove the scheduled task
    ExpandEnvStrings $0 %COMSPEC%
    ExecWait `"$0" /c "SchTasks /Delete /TN name /F"`

    ; delete registry for uninstaller - run as admin
    SetRegView 64
      DeleteRegValue HKCU "SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" "$LOCALAPPDATA\Programs\name\Uninstall name.exe"
    SetRegView 32
      DeleteRegValue HKCU "SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" "$LOCALAPPDATA\Programs\name\Uninstall name.exe"
  ${endIf}
!macroend

package.json包.json

"win": {
  "target": [
    "nsis"
  ],
  "requestedExecutionLevel": "requireAdministrator"
},
"nsis": {
  "include": "installer/windows/installer.nsh",
  "allowElevation": true,
  "deleteAppDataOnUninstall": true,
  "artifactName": "${productName}.${ext}"
},

As mentioned in the documentation , you need to add the following to your electron-builder.json (or the build section of your package.json ) to elevate your installer:文档中所述,您需要将以下内容添加到您的electron-builder.json (或您的package.jsonbuild部分)以提升您的安装程序:

"nsis": {
    "allowElevation": true
}

I found another way, but it will break your "one click" installation:我找到了另一种方法,但它会破坏您的“一键式”安装:

"build": {
    "nsis": {
      "include": "./build/installer.nsh",
      "oneClick": false,
      "perMachine": true,
      "warningsAsErrors": false
    }
  },

Key thing: oneClick false + perMachine true关键:oneClick false + perMachine true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 电子:电子建设者配置 - Electron: electron-builder config 如何从 .msi 安装程序到电子生成器 (nsis) - How to go from .msi installer to electron-builder (nsis) 无法使用电子生成器在Mac上的Windows上为电子应用程序签名 - Unable to sign electron app for Windows on Mac using electron-builder 使用 electron-builder 从 electron 应用程序构建standalone.exe - Build standalone .exe from electron app using electron-builder 电子生成器:卸载程序后如何删​​除深层链接协议? - electron-builder: How can I remove deeplinking protocols once the program is uninstalled? Electron Builder NSIS 在启动时创建快捷方式 - Electron Builder NSIS Create a shortcut in startup 在 Mac 上使用 Electron-builder 共同设计 Windows 版本,但不起作用 - Codesigning a Windows build with electron-builder, on a Mac, not working 将使用电子修建器设置创建的appx安装默认电子图标到我安装的应用程序后 - After installing appx created with electron-builder setting default electron icon to my installed app electron builder:如何在 NSIS 安装程序中自定义字符串值? - electron builder: how to customize the string values in NSIS installer? 在电子生成器之后找出当前正在运行的构建目标 - Find out what build target is currently running after electron-builder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM