Repository: spyder-ide/spyder

Issue:
Windows taskbar icon appears twice, if the Spyder icon is pinned
_From [mor...@hannemose.dk](https://code.google.com/u/106949175155913657293/) on 2014-09-24T10:19:48Z_

Spyder Version:  2.3.1
Python Version:  2.7.8
Qt Version    :  4.8.6, PyQt4 (API v2) 4.11.2 on Windows
pyflakes >=0.5.0:  None (OK)
pep8 >=0.6      :  None (NOK)
IPython >=0.13  :  2.2.0 (OK)
pygments >=1.6  :  1.6 (OK)
pandas >=0.13.1 :  None (NOK)
sphinx >=0.6.6  :  1.2.3 (OK)
rope >=0.9.2    :  0.9.4 (OK)
matplotlib >=1.0:  None (NOK)
sympy >=0.7.0   :  None (NOK)
pylint >=0.25   :  1.3.1 (OK) 

What steps will reproduce the problem?
1. Pin Spyder to the taskbar in Windows 8
   1. Open Spyder 

What is the expected output? What do you see instead?

 I expected the open instance top show up as the pinned icon, thus only taking up one space. 
What I see is in my screenshot, where the left icon is pinned, and the right icon is the running instance. 

Please provide any additional information below

. This issue was introduced by revision f2f29244c2c5 , which resolved issue #1319 . 
(I've never experienced that issue personally). I know it was introduced by that revision, because I tried reverting those changes locally, and the issue went away (only one icon, yay!).
I also posted on that issue, but I figured it's probably correct procedure to open a new issue.

**Attachment:** [SpyderIcon.PNG](http://code.google.com/p/spyderlib/issues/detail?id=1983)

_Original issue: http://code.google.com/p/spyderlib/issues/detail?id=1983_



Discussion:
_From [tbrie...@gmail.com](https://code.google.com/u/102829742279212745962/) on 2015-01-13T04:02:50Z_

Further to this. If Spyder is pinned by running Spyder.exe then pinning the open application the icon changes to that of python.exe. Closing Spyder and clicking the newly pinned icon results in a command line python interpreter opening.

_From [ccordoba12](https://code.google.com/u/ccordoba12/) on 2015-02-08T11:23:55Z_

**Labels:** MS-v2.3.4 Cat-SpyderGUI  

_From [ccordoba12](https://code.google.com/u/ccordoba12/) on 2015-02-08T11:24:19Z_

issue #2150 has been merged into this issue.

Could you try setting the Shortcuts AppUserModelID to "spyderlib.Spyder" using https://code.google.com/p/win7appid/ ?

@TWAC I tried that and it didn't work. Here's my version info:

```
Spyder Version:  2.3.2
Python Version:  2.7.6
Qt Version    :  4.8.6, PyQt4 (API v2) 4.10.4 on Windows
pyflakes >=0.5.0:  0.8.1 (OK)
pep8 >=0.6      :  1.5.7 (OK)
IPython >=0.13  :  2.3.1 (OK)
zmq >=2.1.11    :  14.4.1 (OK)
pygments >=1.6  :  2.0.1 (OK)
pandas >=0.13.1 :  0.15.2 (OK)
sphinx >=0.6.6  :  1.2.3 (OK)
rope >=0.9.2    :  0.9.4 (OK)
matplotlib >=1.0:  1.4.0 (OK)
sympy >=0.7.0   :  0.7.5 (OK)
pylint >=0.25   :  1.4.1 (OK)
```

On windows 10, I have solved this by running the following Python code:

```
from win32com.shell import shellcon
from win32com.propsys import propsys, pscon
import pythoncom

shortcut_path = r"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Anaconda3 (64-bit)\Spyder.lnk"
store = propsys.SHGetPropertyStoreFromParsingName(shortcut_path, None, shellcon.GPS_READWRITE, propsys.IID_IPropertyStore)
store.SetValue(pscon.PKEY_AppUserModel_ID, propsys.PROPVARIANTType(u'spyder.Spyder', pythoncom.VT_LPWSTR))
store.Commit()
```

Note that this only changes the properties of the start menu shortcut, not a shortcut already pinned to the taskbar. However, if you pin to the taskbar (from the start menu shortcut) **after** running the code, then the bug is fixed. Presumably this is because pinning to the taskbar duplicates the shortcut, rather than using the existing shortcut, and the above code would work if I knew where taskbar shortcuts were kept (update: turns out they're in `%AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar`, however running the code on an existing taskbar shortcut doesn't work. This is not hugely surprising to me and I don't think it needs to be accomodated. We just need to fix the creation of shortcuts during the install process, so that it's fixed everywhere prior to people pinning it, and then everything is fine).

Hopefully someone can generalise and integrate the above snippet into the Spyder installation code (in a way that fixes existing installs when they're upgraded) so this bug can be killed once and for all!
Thanks, `SHGetPropertyStoreFromParsingName` however creates
`pywintypes.com_error: (-2147024894, 'The system cannot find the file specified.', None, None)`. Ideas?
I'm guessing the shortcut doesn't exist at the location in my code? Have a look around and see if you can find the shortcut using windows explorer.
successfully executed now it now after finding the right path but it breaks the link and leads to "Spyder (Anaconda3).lnk" not showing up in the start menu any longer ... I'll stick with the duplicate for now, I guess
Could you tell me what version of Spyder and anaconda you have? Maybe something has changed from the version I used
Sure:
`anaconda 2019.10` & `spyder 3.3.6`
Thoughts on this @dalthviz / @jnsebgosselin  ?
Win 7 support ends on January 14, 2020, so I would close this.
@goanpeca The title might say windows 7, but it equally effects windows 8/8.1 and 10. The fix I detailed above (that may need revising because it didn't work for someone else) was developed on Windows 10.

Can you reopen?
Sure
No joy trying that from me Phil. Spyder 4.1.2, conda 4.8.3
@ccaprani (and @NilsDroste) I'll see if I can test with new versions soon.

I did just try it with an older version of Sypder, and I ran into similar errors that have been reported above. The solutions were:

- To first run the code from an elevated command prompt (launch anaconda prompt with admin privileges).
- Run my [above code](https://github.com/spyder-ide/spyder/issues/1983#issuecomment-453904871). If run from a Python interpreter (rather than a .py file), exit the Python interpreter.
- Restart all instances of explorer.exe. The easiest way to achieve this is to restart your PC.

After this the shortcut reappeared in my start menu (it was listed as "new"), although it did take a short time for it to appear. Pinning this resulted in spyder launching with a single icon.
Beautiful work @philipstarkey. I had missed out on restarting explorer and taking the new shortcut! Thanks!
@dalthviz, please take a look at this one.
> @ccaprani (and @NilsDroste) I'll see if I can test with new versions soon.
> 
> I did just try it with an older version of Sypder, and I ran into similar errors that have been reported above. The solutions were:
> 
> * To first run the code from an elevated command prompt (launch anaconda prompt with admin privileges).
> * Run my [above code](https://github.com/spyder-ide/spyder/issues/1983#issuecomment-453904871). If run from a Python interpreter (rather than a .py file), exit the Python interpreter.
> * Restart all instances of explorer.exe. The easiest way to achieve this is to restart your PC.
> 
> After this the shortcut reappeared in my start menu (it was listed as "new"), although it did take a short time for it to appear. Pinning this resulted in spyder launching with a single icon.

Exactly as you say. Only one or two things.
-> You have to delete at first Spyder.lnk from C:\Users\XXXXXX\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Anaconda3 (64-bit)\
-> Then run in administrator mode your hackcode 👍 
-> Then new icon should appears (as when you install new program) in star menu, and this is which should have to be pinned to task bar.

Thank you Phillip!! Great Hack for TOC people (it's a joke) I hate have icons multiplying in my taskbar when you love minimal and non disrupting things!! 🕺 



Resolving patch:
diff --git a/installers/Windows/installer.py b/installers/Windows/installer.py
--- a/installers/Windows/installer.py
+++ b/installers/Windows/installer.py
@@ -311,6 +311,12 @@ def run(python_version, bitness, repo_root, entrypoint, package, icon_path,
                 "installers/Windows/assets/jedi/__main__.py",
                 os.path.join(work_dir, "__main__.py"))
 
+            print("Copying NSIS plugins into discoverable path")
+            shutil.copy(
+                "installers/Windows/assets/nsist/plugins/x86-unicode/"
+                "WinShell.dll",
+                "C:/Program Files (x86)/NSIS/Plugins/x86-unicode/WinShell.dll")
+
             if template:
                 print("Copying template into discoverable path for Pynsist")
                 template_basename = os.path.basename(template)
diff --git a/spyder/utils/programs.py b/spyder/utils/programs.py
--- a/spyder/utils/programs.py
+++ b/spyder/utils/programs.py
@@ -1035,7 +1035,7 @@ def is_spyder_process(pid):
 
         # Valid names for main script
         names = set(['spyder', 'spyder3', 'spyder.exe', 'spyder3.exe',
-                     'bootstrap.py', 'spyder-script.py'])
+                     'bootstrap.py', 'spyder-script.py', 'Spyder.launch.pyw'])
         if running_under_pytest():
             names.add('runtests.py')
 


Test patch: