Skip to content

Set AppUserModelID for unpackaged - #20018

Merged
Carlos Zamora (carlos-zamora) merged 4 commits into
mainfrom
dev/cazamor/aumid
Mar 27, 2026
Merged

Carlos Zamora (carlos-zamora) merged 4 commits into
mainfrom
dev/cazamor/aumid

Conversation

@carlos-zamora

@carlos-zamora Carlos Zamora (carlos-zamora) commented Mar 25, 2026 •

Copy link
Copy Markdown

Summary of the Pull Request

Does what it says on the tin. Sets the AUMID to WindowsTerminal.<hash> with a slightly different prefix based on the branding. The hash is based on the full process image name and user SID.

Extracted from #20013

#endif
const auto path = wil::QueryFullProcessImageNameW<std::wstring>();
const auto hash = til::hash(path);
fmt::format_to(std::back_inserter(aumid), FMT_COMPILE(L".{:016x}"), hash);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this do on x86? just have a bunch of 0s in?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

til::hash returns a size_t, so {:016x} would have the first 8 digits be 0s.

That said, I added the #ifdef _WIN64 branches for consistency with the other places that's done in this file.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you move this up, before the GetCurrentProcessToken block, couldn't you just use the windowClassName as an argument to SetCurrentProcessExplicitAppUserModelID?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for missing this! We wouldn't be able to use the windowClassName as the AUMID because it can't contain spaces (reference).

That said, I can reuse the ifdefs to set the aumid, IsPackaged() check, and hash. Making the change now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also just remove the spaces from the window class! It bears no real meaning.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK with having them be separate for now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(also worth looking at Leonard's comment!)

@microsoft-github-policy-service microsoft-github-policy-service Bot added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Mar 26, 2026
@carlos-zamora

Copy link
Copy Markdown
Author

/azp run

1 similar comment
@carlos-zamora

Copy link
Copy Markdown
Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@carlos-zamora
Carlos Zamora (carlos-zamora) merged commit eea035c into main Mar 27, 2026
18 of 20 checks passed
@carlos-zamora
Carlos Zamora (carlos-zamora) deleted the dev/cazamor/aumid branch March 27, 2026 18:52
Dustin L. Howett (DHowett) pushed a commit that referenced this pull request May 1, 2026
The bug was caused by an AUMID mismatch between the Taskbar's .lnk file
and Windows Terminal. Since no AUMID was associated with the .exe, the
OS automatically creates one for us. However, #20018 added an AUMID for
unpackaged scenarios, so now there was a mismatch, resulting in a new
taskbar entry being created.

To fix this, we check if a .lnk points to our .exe in the taskbar.
There's 3 cases here:
1. no .lnk of interest exists --> set the AUMID normally
2. the .lnk carries our AUMID --> set the AUMID normally
3. the .lnk doesn't have an AUMID (aka uses the auto-resolved one) -->
- for this launch: don't set the AUMID so that we both use the
auto-resolved one
- on next launch: set the AUMID on the .lnk and process so that they all
agree

## Validation Steps Performed
In unpackaged folder, move WindowsTerminal.exe to the taskbar (creates
.lnk)...
✅ Double-click the .exe --> Same taskbar entry is used
✅ Double-click the .exe _again_ --> second window goes to same taskbar
entry

The first window doesn't have to close for this to work. It just * works
*!

Bug introduced in #20018 
Closes #20053
Qiujy (Qmoony) pushed a commit to Qmoony/terminal that referenced this pull request May 11, 2026
The bug was caused by an AUMID mismatch between the Taskbar's .lnk file
and Windows Terminal. Since no AUMID was associated with the .exe, the
OS automatically creates one for us. However, microsoft#20018 added an AUMID for
unpackaged scenarios, so now there was a mismatch, resulting in a new
taskbar entry being created.

To fix this, we check if a .lnk points to our .exe in the taskbar.
There's 3 cases here:
1. no .lnk of interest exists --> set the AUMID normally
2. the .lnk carries our AUMID --> set the AUMID normally
3. the .lnk doesn't have an AUMID (aka uses the auto-resolved one) -->
- for this launch: don't set the AUMID so that we both use the
auto-resolved one
- on next launch: set the AUMID on the .lnk and process so that they all
agree

## Validation Steps Performed
In unpackaged folder, move WindowsTerminal.exe to the taskbar (creates
.lnk)...
✅ Double-click the .exe --> Same taskbar entry is used
✅ Double-click the .exe _again_ --> second window goes to same taskbar
entry

The first window doesn't have to close for this to work. It just * works
*!

Bug introduced in microsoft#20018 
Closes microsoft#20053
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants