Windows. MSI. Unregister Nextcloud folders in SyncRootManager on uninstall.
authoralex-z <blackslayer4@gmail.com>
Mon, 27 Dec 2021 06:59:47 +0000 (08:59 +0200)
committerMatthieu Gallien (Rebase PR Action) <matthieu_gallien@yahoo.fr>
Fri, 7 Jan 2022 17:02:32 +0000 (17:02 +0000)
Signed-off-by: alex-z <blackslayer4@gmail.com>
admin/win/msi/CMakeLists.txt
admin/win/msi/Nextcloud.wxs
admin/win/msi/RegistryCleanup.vbs [new file with mode: 0644]
admin/win/msi/RegistryCleanupCustomAction.wxs [new file with mode: 0644]
admin/win/msi/make-msi.bat.in

index a51aacd8dea56bd4f633c93c74964b25bc0ef286..540bacad990c5d910671525eb3c8f6803cb13c5f 100644 (file)
@@ -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/)
index 7e665a862c5a71d0b27d9d0a8106f80c37008664..8e694b3f69a515168d4565b67f0c753cecf5c3ab 100644 (file)
 
         <!-- 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>
diff --git a/admin/win/msi/RegistryCleanup.vbs b/admin/win/msi/RegistryCleanup.vbs
new file mode 100644 (file)
index 0000000..50e26c8
--- /dev/null
@@ -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
diff --git a/admin/win/msi/RegistryCleanupCustomAction.wxs b/admin/win/msi/RegistryCleanupCustomAction.wxs
new file mode 100644 (file)
index 0000000..a546930
--- /dev/null
@@ -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>
index a8c5d4946b380d4bb028e7c7d601b3ab3621708f..eb14735327fdfe26e2276a9f79ad1bec14a7ba5a 100644 (file)
@@ -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%