Skip to content

Console icon? #11759

Open
Open

Description

I don't know if this has anything to do with conhost, but I can't think of a better place to ask "What's going on here?".

If I give this command to CMD, start "C:\WINDOWS\system32\notepad.EXE" cmd, I get a new instance of CMD in a console with notepad's icon. Why does specifying a title affect the icon?

image

Activity

  1. ghost added
    Needs-Triage
    on Nov 14, 2021
  2. ghost added
    Needs-Tag-Fix
    on Nov 14, 2021
  3. KalleOlaviNiemitalo commented on Nov 15, 2021

    @KalleOlaviNiemitalo

    Seems to be a deliberate feature:

    // search for the application along the path so that we can load its icons (if we didn't find one explicitly in
    // the shortcut)
    const DWORD dwLinkLen = SearchPathW(pwszCurrDir, pwszAppName, nullptr, ARRAYSIZE(wszIconLocation), wszIconLocation, nullptr);
    // If we cannot find the application in the path, then try to fall back and see if the window title is a valid path and use that.
    if (dwLinkLen <= 0 || dwLinkLen > sizeof(wszIconLocation))
    {
    if (PathFileExistsW(pwszTitle) && (wcslen(pwszTitle) < sizeof(wszIconLocation)))
    {
    StringCchCopyW(wszIconLocation, ARRAYSIZE(wszIconLocation), pwszTitle);
    }
    else
    {
    // If all else fails, just stick the app name into the path and try to resolve just the app name.
    StringCchCopyW(wszIconLocation, ARRAYSIZE(wszIconLocation), pwszAppName);
    }
    }

    The logic there seems somewhat odd though; the comment talks about searching "along the path" but the code calls SearchPathW with only pwszCurrDir as the path.

    Plus it uses sizeof(wszIconLocation) in two comparisons where ARRAYSIZE would be correct. Filed as #11761.

  4. vefatica commented on Nov 15, 2021

    @vefatica
    Author

    I can imagine trying to get an icon from STARTUPINFO::lpTitle if STARTUPINFO::dwFlags contains STARTF_TITLEISLINKNAME (or maybe even STARTF_TITLEISAPPID). Otherwise it makes no sense to me. I wouldn't call it a feature.

    Of STARUPINFO::lpTitle, the docs say

    For console processes, this is the title displayed in the title bar if a new console window is created.

    That hardly tells the whole story.

  5. elsaco commented on Nov 15, 2021

    @elsaco

    Vincent Fatica (@vefatica) if you remove the extension, the icon won't be displayed:

    cmd_icon_test

    I don't have the knowledge why it behaves like that!

  6. vefatica commented on Nov 15, 2021

    @vefatica
    Author

    In fact, the code posted by Kalle Olavi Niemitalo (@KalleOlaviNiemitalo) is done outside the if (pLinkSettings->GetStartupFlags() & STARTF_TITLEISLINKNAME) block. It doesn't seem right. It's just a title.

  7. KalleOlaviNiemitalo commented on Nov 15, 2021

    @KalleOlaviNiemitalo

    I assume it is a counterpart to some code in cmd.exe or kernelbase.dll that uses the file name as the window title. Which then makes me wonder if the "Administrator:" prefix can make this not find the correct icon. Perhaps not, because it still has pwszAppName.

  8. vefatica commented on Nov 15, 2021

    @vefatica
    Author

    Back to my first post ... setting the icon to that of notepad is just plain wrong. It's a title. It is not a specification of where to look for an icon.

  9. zadjii-msft commented on Nov 15, 2021

    @zadjii-msft
    Member

    Why does specifying a title affect the icon?

    honestly, I'm not sure anyone on the team is going to have an answer as to why. This is gonna be one of those "features" of the console that's simply always existed, since before we formally owned the console codebase. I don't think we'd really have an answer other than "Huh, yep, it sure does seem to do that".

    I'd be extremely reluctant to change that, undoutably someone somewhere is relying on that behavior to set the icon of their console windows for some reason.

  10. added
    Issue-Question
    Product-Conhost
    Resolution-Answered
    Needs-Discussion
    on Nov 15, 2021
  11. vefatica commented on Nov 15, 2021

    @vefatica
    Author

    since before we formally owned the console codebase

    Maybe so, but it doesn't happen in Windows 7. I wish I had more Windows versions to test on.

    undoutably someone somewhere is relying on that behavior to set the icon of their console windows for some reason.

    That's humorous.

  12. zadjii-msft commented on Nov 15, 2021

    @zadjii-msft
    Member

    undoutably someone somewhere is relying on that behavior to set the icon of their console windows for some reason.

    That's humorous.

    When you've been here as long as us, you can be 100% sure that someone, somewhere, is relying on all sorts of wacky bugs in your codebase 😄

  13. 23 remaining items

  14. sredna commented on Dec 9, 2021

    @sredna

    The funny thing is that way back when we had SEE_MASK_ICON for ShellExecuteEx and I believe it was used to change the console icon but that has not worked for a very long time, NT4 was maybe the last time it actually did anything. Going back even further, Progman in 16-bit Windows had a undocumented way of assigning icons (STARTUPINFO still has a member for it).

    I wish I had more Windows versions to test on.

    Windows 8.1 does not use the icon from the title path.

  15. added
    Help Wanted
    on Mar 10, 2022
  16. ghost removed
    Needs-Tag-Fix
    on Mar 10, 2022
  17. jredfox commented on May 19, 2022

    @jredfox
  18. zadjii-msft commented on Jul 19, 2022

    @zadjii-msft
    Member

    Hmmm. Okay, so breaking this thread down:

    • The console currently uses the "title" as a fallback location to load the icon from, which can be weird.
    • The console does that as of 2017, seemingly to help support WSL distros.
    • This creates a new bug where start "C:\WINDOWS\system32\notepad.EXE" cmd now loads notepad's icon, because we're using the title as a potential icon search path.
    • (TODO) I don't know off hand if there's a better way to support the icons in the WSL distro case (app execution aliases)

    Did I miss anything? I'm down in these weeds as a part of #9458, so this is a prime opportunity to resolve this, if resolvable at all.

  19. LinHeLurking commented on Oct 20, 2022

    @LinHeLurking
  20. DHowett commented on Oct 20, 2022

    @DHowett
  21. LinHeLurking commented on Oct 21, 2022

    @LinHeLurking

    If I open Windows Terminal first then select some predefined profile to open my WSL, it shows correct icon. But if I open corresponding distro xxx.exe, it launches in Windows Terminal without icon, like this:
    image
    And the profile command line is just set as the distro exe. image
    I've tested 2 distros and both of them show wrong icon. Maybe this is related with Windows Terminal?

    I think this is (unfortunately) unrelated to the current issue. However, I'll suggest checking out the icon field in your opensuse-tumbleweed profile settings.

    image

    Apologies first if I misunderstanding current issue 😢

    I've set the Icon field. If I start Windows Terminal first then it shows correct icon like this:
    image

    But if I start Ubuntu directly from start menu, it shows wrong icon:
    image

  22. NewtonChutney commented on Jan 5, 2024

    @NewtonChutney
    * [ ]  (**TODO**) I don't know off hand if there's a better way to support the icons in the WSL distro case (app execution aliases)
    

    Does WT use openconsole/conhost under the hood? If not, we could revert the behaviour regressed just for WSL support from conhost/openconsole? As anyone on WSL would also be on WT imo..

    I've set the Icon field. If I start Windows Terminal first then it shows correct icon like this: image

    But if I start Ubuntu directly from start menu, it shows wrong icon: image

    LinHeLurking, this is related to: #12582 #12755

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-WindowingHelp WantedIssue-BugPriority-3Product-Conhost

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions