瀏覽代碼

Merge pull request #4115 from nextcloud/bugfix/vbs-unregister-vfs

Windows. MSI. Unregister Nextcloud folders in SyncRootManager on uninstall.
Matthieu Gallien 4 年之前
父節點
當前提交
9688ba24ca

+ 2 - 0
admin/win/msi/CMakeLists.txt

@@ -26,6 +26,8 @@ install(FILES
         ${CMAKE_CURRENT_BINARY_DIR}/make-msi.bat
         Platform.wxi
         Nextcloud.wxs
+        RegistryCleanup.vbs
+        RegistryCleanupCustomAction.wxs
         gui/banner.bmp
         gui/dialog.bmp
     DESTINATION msi/)

+ 4 - 0
admin/win/msi/Nextcloud.wxs

@@ -76,12 +76,16 @@
 
         <!-- Uninstall: Remove sync folders from Explorer's Navigation Pane, only effective for the current user (home users) -->
         <Custom Action="RemoveNavigationPaneEntries" After="RemoveFiles">(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")</Custom>
+		
+		<!-- Uninstall: Cleanup the Registry -->
+		<Custom Action="RegistryCleanupCustomAction" After="RemoveFiles">(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")</Custom>
 
         <!-- Schedule Reboot for the Shell Extensions (in silent installation mode only, or if SCHEDULE_REBOOT argument is set-->
         <ScheduleReboot After="InstallFinalize">(SCHEDULE_REBOOT=1) OR NOT (UILevel=2)</ScheduleReboot>
     </InstallExecuteSequence>
 
     <!-- "Add or Remove" Programs Entries -->
+	<Property Id="APPNAME">$(var.AppName)</Property>
     <Property Id="ARPPRODUCTICON">$(var.AppIcon)</Property>
     <Property Id="ARPHELPLINK">$(var.AppHelpLink)</Property>
     <Property Id="ARPURLINFOABOUT">$(var.AppInfoLink)</Property>

+ 54 - 0
admin/win/msi/RegistryCleanup.vbs

@@ -0,0 +1,54 @@
+On Error goto 0
+
+Const HKEY_LOCAL_MACHINE = &H80000002
+
+Const strObjRegistry = "winmgmts:\\.\root\default:StdRegProv"
+
+Function RegistryDeleteKeyRecursive(regRoot, strKeyPath)
+  Set objRegistry = GetObject(strObjRegistry)
+  objRegistry.EnumKey regRoot, strKeyPath, arrSubkeys
+  If IsArray(arrSubkeys) Then
+    For Each strSubkey In arrSubkeys
+      RegistryDeleteKeyRecursive regRoot, strKeyPath & "\" & strSubkey
+    Next
+  End If
+  objRegistry.DeleteKey regRoot, strKeyPath
+End Function
+
+Function RegistryListSubkeys(regRoot, strKeyPath)
+  Set objRegistry = GetObject(strObjRegistry)
+  objRegistry.EnumKey regRoot, strKeyPath, arrSubkeys
+  RegistryListSubkeys = arrSubkeys
+End Function
+
+Function GetUserSID()
+  Dim objWshNetwork, objUserAccount
+  
+  Set objWshNetwork = CreateObject("WScript.Network")
+
+  Set objUserAccount = GetObject("winmgmts://" & objWshNetwork.UserDomain & "/root/cimv2").Get("Win32_UserAccount.Domain='" & objWshNetwork.ComputerName & "',Name='" & objWshNetwork.UserName & "'")
+  GetUserSID = objUserAccount.SID
+End Function
+
+Function RegistryCleanupSyncRootManager()
+  strSyncRootManagerKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\SyncRootManager"
+
+  arrSubKeys = RegistryListSubkeys(HKEY_LOCAL_MACHINE, strSyncRootManagerKeyPath)
+  
+  If IsArray(arrSubkeys) Then
+    arrSubkeys=Filter(arrSubkeys, Session.Property("APPNAME"))
+  End If
+  If IsArray(arrSubkeys) Then
+    arrSubkeys=Filter(arrSubkeys, GetUserSID())
+  End If
+
+  If IsArray(arrSubkeys) Then
+    For Each strSubkey In arrSubkeys
+      RegistryDeleteKeyRecursive HKEY_LOCAL_MACHINE, strSyncRootManagerKeyPath & "\" & strSubkey
+    Next
+  End If
+End Function
+
+Function RegistryCleanup()
+  RegistryCleanupSyncRootManager()
+End Function

+ 7 - 0
admin/win/msi/RegistryCleanupCustomAction.wxs

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
+   <Fragment>
+      <Binary Id="RegistryCleanup" SourceFile="RegistryCleanup.vbs"/>
+      <CustomAction Id='RegistryCleanupCustomAction' BinaryKey="RegistryCleanup" VBScriptCall="RegistryCleanup" Return="ignore" Execute="immediate"/>
+   </Fragment>
+</Wix>

+ 2 - 2
admin/win/msi/make-msi.bat.in

@@ -17,10 +17,10 @@ Rem Generate collect.wxs
 if %ERRORLEVEL% neq 0 exit %ERRORLEVEL%
 
 Rem Compile en-US (https://www.firegiant.com/wix/tutorial/transforms/morphing-installers/)
-"%WIX%\bin\candle.exe" -dcodepage=1252 -dPlatform=%BuildArch% -arch %BuildArch% -dHarvestAppDir="%HarvestAppDir%" -ext WixUtilExtension NCMsiHelper.wxs WinShellExt.wxs collect.wxs Nextcloud.wxs
+"%WIX%\bin\candle.exe" -dcodepage=1252 -dPlatform=%BuildArch% -arch %BuildArch% -dHarvestAppDir="%HarvestAppDir%" -ext WixUtilExtension NCMsiHelper.wxs WinShellExt.wxs collect.wxs Nextcloud.wxs RegistryCleanupCustomAction.wxs
 if %ERRORLEVEL% neq 0 exit %ERRORLEVEL%
 
 Rem Link MSI package
-"%WIX%\bin\light.exe" -sw1076 -ext WixUIExtension -ext WixUtilExtension -cultures:en-us NCMsiHelper.wixobj WinShellExt.wixobj collect.wixobj Nextcloud.wixobj -out "@MSI_INSTALLER_FILENAME@"
+"%WIX%\bin\light.exe" -sw1076 -ext WixUIExtension -ext WixUtilExtension -cultures:en-us NCMsiHelper.wixobj WinShellExt.wixobj collect.wixobj Nextcloud.wixobj RegistryCleanupCustomAction.wixobj -out "@MSI_INSTALLER_FILENAME@"
 
 exit %ERRORLEVEL%