Repository: spyder-ide/spyder

Issue:
App association error
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

- In 'Preferences', 'Files' section I tried to associate an existing application to a specific format to be opened with;
- Spyder crushed telling me to report the issue. 

### Traceback
```python-traceback
Traceback (most recent call last):
  File "C:\Users\SX578CX\AppData\Local\anaconda3\envs\spyder-env\Lib\site-packages\spyder\plugins\explorer\widgets\fileassociations.py", line 495, in add_application
    self._dlg_applications = ApplicationsDialog(self)
                             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\SX578CX\AppData\Local\anaconda3\envs\spyder-env\Lib\site-packages\spyder\plugins\explorer\widgets\fileassociations.py", line 143, in __init__
    self.setup()
  File "C:\Users\SX578CX\AppData\Local\anaconda3\envs\spyder-env\Lib\site-packages\spyder\plugins\explorer\widgets\fileassociations.py", line 150, in setup
    apps = get_installed_applications()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\SX578CX\AppData\Local\anaconda3\envs\spyder-env\Lib\site-packages\spyder\utils\programs.py", line 533, in get_installed_applications
    apps = _get_win_applications()
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\SX578CX\AppData\Local\anaconda3\envs\spyder-env\Lib\site-packages\spyder\utils\programs.py", line 430, in _get_win_applications
    files = [f for f in os.listdir(location)
                        ^^^^^^^^^^^^^^^^^^^^
PermissionError: [WinError 5] Access is denied: 'C:\\Program Files (x86)\\Hive Streaming\\'
```

## Versions

* Spyder version: 5.4.3  (conda)
* Python version: 3.11.3 64-bit
* Qt version: 5.15.6
* PyQt5 version: 5.15.7
* Operating System: Windows 10

### Dependencies

```
# Mandatory:
atomicwrites >=1.2.0                             :  1.4.1 (OK)
chardet >=2.0.0                                  :  5.1.0 (OK)
cloudpickle >=0.5.0                              :  2.2.1 (OK)
cookiecutter >=1.6.0                             :  2.1.1 (OK)
diff_match_patch >=20181111                      :  20200713 (OK)
intervaltree >=3.0.2                             :  3.1.0 (OK)
IPython >=7.31.1,<9.0.0,!=8.8.0,!=8.9.0,!=8.10.0 :  8.13.2 (OK)
jedi >=0.17.2,<0.19.0                            :  0.18.2 (OK)
jellyfish >=0.7                                  :  0.9.0 (OK)
jsonschema >=3.2.0                               :  4.17.3 (OK)
keyring >=17.0.0                                 :  23.13.1 (OK)
nbconvert >=4.0                                  :  7.3.1 (OK)
numpydoc >=0.6.0                                 :  1.5.0 (OK)
paramiko >=2.4.0                                 :  3.1.0 (OK)
parso >=0.7.0,<0.9.0                             :  0.8.3 (OK)
pexpect >=4.4.0                                  :  4.8.0 (OK)
pickleshare >=0.4                                :  0.7.5 (OK)
psutil >=5.3                                     :  5.9.5 (OK)
pygments >=2.0                                   :  2.15.1 (OK)
pylint >=2.5.0,<3.0                              :  2.17.4 (OK)
pylint_venv >=2.1.1                              :  3.0.1 (OK)
pyls_spyder >=0.4.0                              :  0.4.0 (OK)
pylsp >=1.7.2,<1.8.0                             :  1.7.2 (OK)
pylsp_black >=1.2.0                              :  1.2.1 (OK)
qdarkstyle >=3.0.2,<3.2.0                        :  3.1 (OK)
qstylizer >=0.2.2                                :  0.2.2 (OK)
qtawesome >=1.2.1                                :  1.2.3 (OK)
qtconsole >=5.4.2,<5.5.0                         :  5.4.3 (OK)
qtpy >=2.1.0                                     :  2.3.1 (OK)
rtree >=0.9.7                                    :  1.0.1 (OK)
setuptools >=49.6.0                              :  67.7.2 (OK)
sphinx >=0.6.6                                   :  7.0.0 (OK)
spyder_kernels >=2.4.3,<2.5.0                    :  2.4.3 (OK)
textdistance >=4.2.0                             :  4.5.0 (OK)
three_merge >=0.1.1                              :  0.1.1 (OK)
watchdog >=0.10.3                                :  3.0.0 (OK)
zmq >=22.1.0                                     :  25.0.2 (OK)

# Optional:
cython >=0.21                                    :  None (NOK)
matplotlib >=3.0.0                               :  None (NOK)
numpy >=1.7                                      :  None (NOK)
pandas >=1.1.1                                   :  None (NOK)
scipy >=0.17.0                                   :  None (NOK)
sympy >=0.7.3                                    :  None (NOK)
```



Discussion:
Hi @Enrik9294 thank you for the feedback! Seems like a permission error since Spyder is installed in an env from a current user anaconda installation right? Could you test what happens if you run Spyder with admin rights?

Any new info in order to better understand this issue is greatly appreciated. Let us know!
> Hi @Enrik9294 thank you for the feedback! Seems like a permission error since Spyder is installed in an env from a current user anaconda installation right? Could you test what happens if you run Spyder with admin rights?
> 
> 
> 
> Any new info in order to better understand this issue is greatly appreciated. Let us know!

Useful tip!
I run Spyder as admin and all went good, really thanks!
Awesome! Thank you for letting us know @Enrik9294 ! Probably we need to capture such an error and show a message indicating the need of admin privileges in order to use the application association or add some other logic to handle the exception gracefully, what do you think @ccordoba12 ?
Yep, I agree. I think the simplest thing would be to add a message telling users that the feature is unavailable for non-admin users on Windows.

Resolving patch:
diff --git a/spyder/plugins/explorer/widgets/fileassociations.py b/spyder/plugins/explorer/widgets/fileassociations.py
--- a/spyder/plugins/explorer/widgets/fileassociations.py
+++ b/spyder/plugins/explorer/widgets/fileassociations.py
@@ -147,7 +147,13 @@ def setup(self, applications=None):
         QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
         self.list.clear()
         if applications is None:
-            apps = get_installed_applications()
+            # This is necessary to avoid an error on Windows for non-admin
+            # accounts.
+            # Fixes spyder-ide/spyder#20907
+            try:
+                apps = get_installed_applications()
+            except PermissionError:
+                apps = []
         else:
             apps = applications
 


Test patch: