[英]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.json
的build
部分)以提升您的安装程序:
"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.