uninstall.py

changeset 6510
d8fd663f86ef
parent 6509
884182bfd25c
child 6645
ad476851d7e0
--- a/uninstall.py	Thu Sep 20 19:48:56 2018 +0200
+++ b/uninstall.py	Fri Sep 21 20:21:31 2018 +0200
@@ -219,24 +219,41 @@
     """
     Clean up the Desktop and Start Menu entries for Windows.
     """
-    regPath = r"Software\Microsoft\Windows\CurrentVersion\Explorer" \
-              r"\User Shell Folders"
+    try:
+        from pywintypes import com_error        # __IGNORE_WARNING__
+    except ImportError:
+        # links were not created by install.py
+        return
+    
+    regPath = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer" + \
+              "\\User Shell Folders"
+    
     # 1. cleanup desktop links
     regName = "Desktop"
-    desktopFolder = os.path.normpath(
-            os.path.expandvars(getWinregEntry(regName, regPath)))
-    for linkName in windowsDesktopNames():
-        linkPath = os.path.join(desktopFolder, linkName)
-        if os.path.exists(linkPath):
-            os.remove(linkPath)
+    desktopEntry = getWinregEntry(regName, regPath)
+    if desktopEntry:
+        desktopFolder = os.path.normpath(os.path.expandvars(desktopEntry))
+        for linkName in windowsDesktopNames():
+            linkPath = os.path.join(desktopFolder, linkName)
+            if os.path.exists(linkPath):
+                try:
+                    os.remove(linkPath)
+                except EnvironmentError:
+                    # maybe restrictions prohibited link removal
+                    print("Could not remove '{0}'.".format(linkPath))
     
     # 2. cleanup start menu entry
     regName = "Programs"
-    programsFolder = os.path.normpath(
-        os.path.expandvars(getWinregEntry(regName, regPath)))
-    eric6EntryPath = os.path.join(programsFolder, windowsProgramsEntry())
-    if os.path.exists(eric6EntryPath):
-        shutil.rmtree(eric6EntryPath)
+    programsEntry = getWinregEntry(regName, regPath)
+    if programsEntry:
+        programsFolder = os.path.normpath(os.path.expandvars(programsEntry))
+        eric6EntryPath = os.path.join(programsFolder, windowsProgramsEntry())
+        if os.path.exists(eric6EntryPath):
+            try:
+                shutil.rmtree(eric6EntryPath)
+            except EnvironmentError:
+                # maybe restrictions prohibited link removal
+                print("Could not remove '{0}'.".format(eric6EntryPath))
 
 
 def uninstallLinuxSpecifics():

eric ide

mercurial