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. 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.
. 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? 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:
"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.
!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
"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:
"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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.