Ver código fonte

fix(#2230) - Unable to uninstall when using Skip UAC task (#2231)

Ben Briggs 4 anos atrás
pai
commit
83786ce8a4

+ 5 - 0
.changes/wix-uninstall-skip-uac-task.md

@@ -0,0 +1,5 @@
+--
+"tauri-bundler": patch
+--
+
+Added script to uninstall the Skip-UAC Windows Task during application uninstall.

+ 11 - 0
tooling/bundler/src/bundle/windows/msi/wix.rs

@@ -575,6 +575,17 @@ pub fn build_wix_app_installer(
     let install_script_content = skip_uac_task_installer.render("install-task.ps1", &data)?;
     write(&temp_ps1_path, install_script_content.clone())?;
 
+    // Create the Powershell script to uninstall the task
+    let mut skip_uac_task_uninstaller = Handlebars::new();
+    let xml = include_str!("../templates/uninstall-task.ps1");
+    skip_uac_task_uninstaller
+      .register_template_string("uninstall-task.ps1", xml)
+      .map_err(|e| e.to_string())
+      .expect("Failed to setup Update Task Uninstaller handlebars");
+    let temp_ps1_path = output_path.join("uninstall-task.ps1");
+    let install_script_content = skip_uac_task_uninstaller.render("uninstall-task.ps1", &data)?;
+    write(&temp_ps1_path, install_script_content.clone())?;
+
     data.insert("enable_elevated_update_task", to_json(true));
   }
 

+ 5 - 3
tooling/bundler/src/bundle/windows/templates/main.wxs

@@ -94,6 +94,9 @@
             <Component Id="UpdateTaskInstaller" Guid="011F25ED-9BE3-50A7-9E9B-3519ED2B9932" Win64="$(var.Win64)">
                 <File Id="UpdateTaskInstaller" Source="install-task.ps1" KeyPath="yes" Checksum="yes"/>
             </Component>
+            <Component Id="UpdateTaskUninstaller" Guid="D4F6CC3F-32DC-5FD0-95E8-782FFD7BBCE1" Win64="$(var.Win64)">
+                <File Id="UpdateTaskUninstaller" Source="uninstall-task.ps1" KeyPath="yes" Checksum="yes"/>
+            </Component>
             {{/if}}
             {{{resources}}}
             <Component Id="CMP_UninstallShortcut" Guid="*">
@@ -158,6 +161,7 @@
             {{#if enable_elevated_update_task}}
                 <ComponentRef Id="UpdateTask" />
                 <ComponentRef Id="UpdateTaskInstaller" />
+                <ComponentRef Id="UpdateTaskUninstaller" />
             {{/if}}
 
             <Feature Id="ShortcutsFeature"
@@ -232,9 +236,7 @@
             Id="DeleteUpdateTask"
             Return="check"
             Directory="INSTALLDIR"
-            Execute="deferred"
-            Impersonate="no"
-            ExeCommand="powershell.exe -WindowStyle hidden &quot;schtasks /DELETE /TN 'Update {{{product_name}}} - Skip UAC' /F&quot;" />
+            ExeCommand="powershell.exe -WindowStyle hidden .\uninstall-task.ps1" />
         <InstallExecuteSequence>
             <Custom Action="DeleteUpdateTask" Before='InstallFinalize'>
                 (REMOVE = "ALL") AND NOT UPGRADINGPRODUCTCODE

+ 23 - 0
tooling/bundler/src/bundle/windows/templates/uninstall-task.ps1

@@ -0,0 +1,23 @@
+# Copyright 2019-2021 Tauri Programme within The Commons Conservancy
+# SPDX-License-Identifier: Apache-2.0
+# SPDX-License-Identifier: MIT
+# Adapted from https://superuser.com/a/532109
+param([switch]$Elevated)
+
+function Test-Admin {
+    $currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
+    $currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
+}
+
+if ((Test-Admin) -eq $false) {
+    if ($elevated) {
+        # tried to elevate, did not work, aborting
+    }
+    else {
+        $ArgList = ('-File "{0}" -Elevated' -f $myinvocation.MyCommand.Definition)
+        Start-Process powershell.exe -WindowStyle hidden -Verb RunAs -ArgumentList $ArgList
+    }
+    exit
+}
+
+SCHTASKS.EXE /DELETE /TN 'Update {{{product_name}}} - Skip UAC' /F