winget-cli icon indicating copy to clipboard operation
winget-cli copied to clipboard

Disable adding a shortcut on the desktop for upgrades

Open D0J0P opened this issue 3 years ago • 34 comments

Brief description of your issue

When upgrading packages using Winget, it adds a new shortcut to my desktop when I didn't have one already.

Steps to reproduce

Open Cmd, type Winget Upgrade [-id of package or --all] Watch new desktop shortcuts being created on your desktop.

Expected behavior

That it wouldn't create a new desktop shortcut for programs I already have installed.

Actual behavior

Winget adds a new desktop shortcut after upgrading packages automatically.

Environment

winget --info
Windows Package Manager v1.1.12653
Copyright (c) Microsoft Corporation. All rights reserved.

Windows: Windows.Desktop v10.0.19042.1237
Package: Microsoft.DesktopAppInstaller v1.16.12653.0

D0J0P avatar Oct 03 '21 16:10 D0J0P

Unfortunately unless a specific installer has a flag for not creating the shortcut there might not be much winget can do

Masamune3210 avatar Oct 03 '21 17:10 Masamune3210

What app are you experiencing this with @D0J0P? Maybe we can fix it.

jedieaston avatar Oct 04 '21 15:10 jedieaston

@D0J0P I believe @Masamune3210 is correct. I'll keep this feature open to help with duplicate requests. We could also consider settings for this in the future, but we will likely still be depending on the installer.

denelon avatar Oct 04 '21 15:10 denelon

What app are you experiencing this with @D0J0P? Maybe we can fix it.

I was experiencing it with Amazon Kindle, Bitwarden and I think MP3Tag.

D0J0P avatar Oct 07 '21 16:10 D0J0P

And Spotify and MegaSync

jlssmt avatar Oct 22 '21 17:10 jlssmt

MP3Tag

Their installer is written in NSIS. You would have to ask the application author if there is a switch you can pass to the installer.

It does seem to support an answer file (Mp3tagSetup.ini):

[shortcuts]
startmenu=1
desktop=0
explorer=1
quicklaunch=1

sredna avatar Oct 22 '21 22:10 sredna

Please consider adding this feature. The vast majority of apps are adding desktop icons and to put the responsibility on the devs of those apps rather than allowing control to lie with winget doesn't make sense. I understand that the app may be the one adding the desktop icon, but if you can force the app devs to provide an unattended installer, you can also force them to heed a --noicon flag. #freethedesktop

objecttothis avatar Oct 26 '21 06:10 objecttothis

if you can force the app devs to provide an unattended installer

That's the thing though; Microsoft isn't. It's just that most developers create silent installers anyway, and they don't create noicon flags. I don't know why.

I wonder if winget could just look after install and see if there are any .lnk files on the desktop pointing to the app that was just installed and delete them (this probably won't be possible until there's more in-depth tracking of installs, but it's worth thinking about).

jedieaston avatar Oct 26 '21 12:10 jedieaston

@jedieaston I may be mistaken but I thought I remember reading that the entry will be rejected in the repo if the installer isn't unattended.

objecttothis avatar Oct 26 '21 13:10 objecttothis

That's true, but we didn't go tell anyone to make a silent installer, it just happened that most developers do create them. If we also said "Thou shalt add a flag to prevent making desktop icons", we would have about fifty apps in the repo since most installers aren't that nice.

The big thing with winget has been, to borrow a phrase, "taking the world as it is, not as we'd like it to be". The world already has silent installers. Most applications don't expect the user to install over the previous version to upgrade, so their installers don't necessarily have a special case that prevents things like icons (especially if they homegrew something). I think this would be a good thing for the client to handle.

jedieaston avatar Oct 26 '21 14:10 jedieaston

"taking the world as it is, not as we'd like it to be".

That being said, some kind of official guideline would be nice. The old Windows logo program comes close but it's not specifically for installers and how they can be automated. Microsoft also has the power to standardize ARP registry entries related to upgrades and shortcut creation.

With some kind of official document in hand, we, the community, can request changes from the developers. Perhaps not the big names at first but certainly smaller fish and open source projects.

sredna avatar Oct 27 '21 00:10 sredna

@sredna we've been taking baby steps in this area. Most of the documentation has been in terms of "best practices". I agree it would help to have a clear direction / intent for publishers to follow. This is something that will certainly take time, and need to evolve. We've been capturing classes of problems, and looking at how to classify what we see. Think of a "good", "better", "best" model. We can then more clearly articulate what the best practices are, and what less than optimal scenarios we can compensate for.

denelon avatar Oct 27 '21 01:10 denelon

This is something that will certainly take time, and need to evolve.

It is a bit of a chicken/egg problem. I'd be happy to update the examples we (NSIS/nullsoft) ship with whatever is decided is the optimal solution but I also don't want to lead people down the wrong path prematurely.

In its simplest form it might just be if (alreadyinstalled() && thisVer > existingVer) default_shortcuts_to_unchecked();, this would at least handle the case where a user re-installs the same version to repair a broken install assuming creating shortcuts is defined as part of a repair operation. A more complex form would be for Winget to be involved somehow on upgrades, be it a command-line switch or setting a Microsoft reserved ARP value in a existing uninstall key.

End-users also have the option of marking the .lnk files as hidden, this should work for most people unless you have the show hidden files option on.

sredna avatar Nov 01 '21 15:11 sredna

Just check the items on the desktop for all users and the currently logged in user, diff to post-install and then revert changes.

Boom. Done. No developer sanity required.

GlassedSilver avatar Jan 12 '22 20:01 GlassedSilver

I think the reason we can’t do that is because of the user saves a document to the desktop during a install we won’t know who did it necessarily.

If we could figure out what was there pre and post install and then look for .lnk files that point to directories modified with the installer, then we’d be on to something. But I don’t know if the “track installed packages” feature is planning to be that deep.

jedieaston avatar Jan 12 '22 21:01 jedieaston

Right, well... As you mentioned that'd be something that sounds plausible to do in addition.

I think .lnks getting yote if they point to a dir that is home to applications in general could be a worthwhile intermediary option.

Additionally I'd propose to offer a standard for pre-defining certain common options for an unattended silent installer to follow.

I'm sure if winget defines default values for certain commonly expected user inputs the installer could then follow them or if the installer isn't ready to follow them yet alert the user and ask what to do. (proceed without args or cancel)

Because I'm not eager to try out random installers and going with the default setup only to figure out later on that the default setup includes today's equivalent to browser toolbars and Bonzi Buddy if you get my drift.

Cause the whole thing about shortcuts on the desktop is just the tip of the iceberg.

If winget would push for substantial change in how installers on Windows operate in this way in general this would be a MASSIVE gain for Windows in general.

GlassedSilver avatar Jan 13 '22 07:01 GlassedSilver

Can we please push for this? This issue is the biggest annoyance I have with Winget at the moment.

Jackaed avatar Aug 11 '23 07:08 Jackaed

how about just giving the option at least for those package setups that do support it. afaik there's no way at all right now so even if there is a no-desktop-icon option in the setup, it can't be used. And just ignore it for the setups that don't support it.

xzenor avatar Sep 26 '23 06:09 xzenor

I also want this feature.

I threw together two ugly tiny wrappers based on my winget/scoop/choco/wsl-dist mix system wide upgrade script. What it does is that it scan the desktop first and after clears any new item created when done. (So don't save a document on your desktop while updateing/installing)

# PowerShell 7.3.7
function winget-install {
    $Desktops =    "$env:USERPROFILE\Desktop\$ShortcutName",
    "C:\Users\Default\Desktop\$ShortcutName",
    "C:\Users\Public\Desktop\$ShortcutName" 
    $preDesktop = @()
    foreach ($Desktop in $Desktops) {
        $items = Get-ChildItem -Path $Desktop -Name -Include "*.lnk"
        foreach ($item in $items) {
            $preDesktop += $item
        }
    }
    
    # install WinGet
    winget install $args 
    
    # Cleaning up new unwhanted desktop icons
    Write-Host "Cleaning up WinGet created desktop icons...`n"
    $newDesktopLinks = @()
    foreach ($Desktop in $Desktops) {
        $items = Get-ChildItem -Path $Desktop -Name -Include "*.lnk"
        foreach ($item in $items) {
            if ($preDesktop -contains $item ) {
            } else {
                $newDesktopLinks += $item
            }
        }
    }
    foreach ($item in $newDesktopLinks) {
        Remove-Item -Path "$env:USERPROFILE\Desktop\$item" >$null 2>&1
        Remove-Item -Path "C:\Users\Default\Desktop\$item" >$null 2>&1
        Remove-Item -Path "C:\Users\Public\Desktop\$item" >$null 2>&1
        Write-Host "Cleaned up $item" -ForegroundColor DarkGray
    }
}

function winget-upgrade {
    $Desktops =    "$env:USERPROFILE\Desktop\$ShortcutName",
    "C:\Users\Default\Desktop\$ShortcutName",
    "C:\Users\Public\Desktop\$ShortcutName" 
    $preDesktop = @()
    foreach ($Desktop in $Desktops) {
        $items = Get-ChildItem -Path $Desktop -Name -Include "*.lnk"
        foreach ($item in $items) {
            $preDesktop += $item
        }
    }
    
    # Update WinGet
    winget upgrade $args
    
    # Cleaning up new unwhanted desktop icons
    Write-Host "Cleaning up WinGet created desktop icons...`n"
    $newDesktopLinks = @()
    foreach ($Desktop in $Desktops) {
        $items = Get-ChildItem -Path $Desktop -Name -Include "*.lnk"
        foreach ($item in $items) {
            if ($preDesktop -contains $item ) {
            } else {
                $newDesktopLinks += $item
            }
        }
    }
    foreach ($item in $newDesktopLinks) {
        Remove-Item -Path "$env:USERPROFILE\Desktop\$item" >$null 2>&1
        Remove-Item -Path "C:\Users\Default\Desktop\$item" >$null 2>&1
        Remove-Item -Path "C:\Users\Public\Desktop\$item" >$null 2>&1
        Write-Host "Cleaned up $item" -ForegroundColor DarkGray
    }
}

In action:

~ 
PS > pwsh -v
PowerShell 7.3.7
~ 
PS > winget-install Discord.Discord --force
Found Discord [Discord.Discord] Version 1.0.9018
This application is licensed to you by its owner.
Microsoft is not responsible for, nor does it grant any licenses to, third-party packages.
Successfully verified installer hash
Starting package install...
Successfully installed
Cleaning up WinGet created desktop icons...

Cleaned up Discord.lnk
~ took 10s
PS >

AndreasBrostrom avatar Oct 07 '23 19:10 AndreasBrostrom

I join this request, it is just a surprise not able to have this kind of feature by design, else changing a registry somewhere.... Or would be nice if able to add a global settings in the Winget settings file: So we can deactivate the default desktop shortcuts.

Winget settings

{ "$schema": "https://aka.ms/winget-settings.schema.json",

// For documentation on these settings, see: https://aka.ms/winget-settings
// "source": {
//    "autoUpdateIntervalInMinutes": 5
// },

}

Pascal-KOTTE avatar Oct 30 '23 00:10 Pascal-KOTTE

@AndreasBrostrom very nice, but it can be simplified a lot:

# PowerShell 7.3.7
function winget-install {
    $preDesktop = [Environment]::GetFolderPath('Desktop'), [Environment]::GetFolderPath('CommonDesktop') |
        Get-ChildItem -Filter '*.lnk'
    
    # install WinGet
    winget install $args 

    $postDesktop = [Environment]::GetFolderPath('Desktop'), [Environment]::GetFolderPath('CommonDesktop') |
        Get-ChildItem -Filter '*.lnk'    

    # Cleaning up new unwhanted desktop icons
    Write-Host "Cleaning up WinGet created desktop icons..."
    $postDesktop | Where-Object FullName -notin $preDesktop.FullName | Foreach-Object {
        Remove-Item -LiteralPath $_.FullName
        Write-Host "Cleaned up $($_.Name)" -ForegroundColor DarkGray
    }
}

function winget-upgrade {
    $preDesktop = [Environment]::GetFolderPath('Desktop'), [Environment]::GetFolderPath('CommonDesktop') |
        Get-ChildItem -Filter '*.lnk'
    
    # Update WinGet
    winget upgrade $args

    $postDesktop = [Environment]::GetFolderPath('Desktop'), [Environment]::GetFolderPath('CommonDesktop') |
        Get-ChildItem -Filter '*.lnk'    

    # Cleaning up new unwhanted desktop icons
    Write-Host "Cleaning up WinGet created desktop icons..."
    $postDesktop | Where-Object FullName -notin $preDesktop.FullName | Foreach-Object {
        Remove-Item -LiteralPath $_.FullName
        Write-Host "Cleaned up $($_.Name)" -ForegroundColor DarkGray
    }
}

This will also work for users who have their desktop redirected to a non-standard path (e.g. because they're using OneDrive) because it isn't hardcoded to look at the default location $env:USERPROFILE\Desktop anymore.

jantari avatar Nov 18 '23 02:11 jantari

Any update on this? I'm new on WingetUI but it's starting to bother me a lot and it's sad since it's an awesome piece of software.

bitkris-dev avatar Jan 11 '24 17:01 bitkris-dev

we desperately need a global config to override this behavior, like:

[shortcuts]
startmenu=0
desktop=0
explorer=0
quicklaunch=0

hrsa avatar Jan 13 '24 12:01 hrsa

Any update on this? I'm new on WingetUI but it's starting to bother me a lot and it's sad since it's an awesome piece of software. WingetUI ? from https://github.com/marticliment/wingetui ?? You are not on the good place @bitkris-dev !

Pascal-KOTTE avatar Jan 26 '24 20:01 Pascal-KOTTE

@jantari Why not using FileSystemWatchers instead? This would remove the desktop icons immediately after they have been created:

function winget-install {
  # Register events for removing desktop shortcuts
  foreach ($dir in "Desktop","CommonDesktop") {
    $Watcher = [System.IO.FileSystemWatcher]::new([Environment]::GetFolderPath($dir),"*.lnk")
    [void](Register-ObjectEvent -InputObject $Watcher -EventName "Created" -SourceIdentifier $dir -Action {Remove-Item -Force $EventArgs.FullPath})
  }

  # Install WinGet
  winget install $args

  # Unregister Events
  foreach ($dir in "Desktop","CommonDesktop") {Unregister-Event -SourceIdentifier $dir}
}

TK1987 avatar Apr 16 '24 12:04 TK1987

I'd like this feature too. Firefox, Teamviewer and Ubisoft Connect are 3 culprits that I have installed that will always add a desktop shortcut on upgrade.

MrAbidPatel avatar Apr 24 '24 02:04 MrAbidPatel

Same request here. Such a feature would be nice to not clutter the desktop.

I think also a workaround (like the powershell script above) but implemented in winget would be nice.

thx

popy2k14 avatar May 09 '24 14:05 popy2k14

Actual guidance from the Windows team would be nice. Only Microsoft has the power to standardize ARP entries like NoDesktopShortcut etc.

whindsaks avatar May 09 '24 14:05 whindsaks

Microsoft has actually been quite hands-off when it comes to installers for the most part, historically. That's half the reason we are in this mess to begin with.

Also, adding such a entry to the ARP key wouldn't solve anything, it would need to be an argument passed into the installer, since WinGet handles upgrades by downloading and launching the installer from the product's website and letting the installer handle the upgrade with its own logic.

Masamune3210 avatar May 15 '24 00:05 Masamune3210

Also, adding such a entry to the ARP key wouldn't solve anything

It would, it would encourage developers to add support for this feature just like people did for DisplayIcon and all the other standard entries that were invented for Windows 2000.

It would be even better if Microsoft could standardize the switches used to disable shortcut creation but it is a bit too late for that. The MSDN description for "NoDesktopShortcut" could at least note that installers are encouraged to support a command line switch.

If NoDesktopShortcut gained wide support, WinGet could even set it before starting the upgrade. That would even work for installers without a command line switch.

(Creating a desktop shortcut goes against the Windows Logo guidelines for the past 25 years but nobody really cares about that it seems)

whindsaks avatar May 15 '24 00:05 whindsaks