Skip to content

New Shell Integration PowerToy: Copy as UNC#46056

Open
RamblingGeekUK wants to merge 13 commits intomicrosoft:mainfrom
RamblingGeekUK:users/wtt/copy-as-unc
Open

New Shell Integration PowerToy: Copy as UNC#46056
RamblingGeekUK wants to merge 13 commits intomicrosoft:mainfrom
RamblingGeekUK:users/wtt/copy-as-unc

Conversation

@RamblingGeekUK
Copy link

@RamblingGeekUK RamblingGeekUK commented Mar 10, 2026

Adds Copy as UNC as a Shell Integration toggle under File Explorer Add-ons.
When enabled, right-clicking a file or folder on a mapped network drive shows a
"Copy as UNC path" entry in the Windows 11 context menu. Invoking it resolves the
drive letter to its UNC path (via WNetGetUniversalNameW) and copies it to the
clipboard.

Implemented as a Windows 11 sparse MSIX IExplorerCommand shell extension,
following the FileLocksmith pattern. The toggle lives in Settings → File Explorer
Add-ons → Shell Integration, per feedback from the PowerToys team.

PR Checklist

  • Closes: Copy as UNC #35507
  • Communication: Discussed with core contributors. Team requested the
    feature be placed under File Explorer Add-ons (Shell Integration section)
    rather than as a standalone module — implemented accordingly.
  • Tests: No automated tests. Validated manually (see Validation Steps).
  • Localization: Two new end-user strings added to Resources.resw:
    FileExplorerPreview_ShellIntegration.Header ("Shell integration") and
    FileExplorerPreview_CopyAsUNC_Enable.Header ("Copy as UNC").
  • Dev docs: Not updated — happy to file a docs PR if the team requires it.
  • New binaries: Added on the required places.
    • ESRPSigning_core.json — added PowerToys.CopyAsUNCExt.dll,
      PowerToys.CopyAsUNCContextMenu.dll, CopyAsUNCContextMenuPackage.msix
    • installer/PowerToysSetupVNext/CopyAsUNC.wxs — new installer fragment
      for Assets\CopyAsUNC\ folder cleanup on uninstall (mirrors
      FileLocksmith.wxs)
    • Product.wxsCopyAsUNCComponentGroup referenced
    • PowerToysInstallerVNext.wixprojCopyAsUNC.wxs compiled, .bk
      restore added to post-build event
    • generateAllFileComponents.ps1 — asset file component generation added
    • YML for CI pipeline — no new test projects; no change needed
    • YML for signed pipeline — please advise if an entry is required

Detailed Description of the Pull Request / Additional comments

New files:

  • src/modules/CopyAsUNC/CopyAsUNCContextMenu/IExplorerCommand COM DLL
    registered via sparse MSIX package. Reads enabled/extended-menu settings,
    checks the selected item is on a mapped network drive (DRIVE_REMOTE), resolves
    UNC via WNetGetUniversalNameW, and writes the result to the clipboard. Icon
    returned from GetIcon as a multi-size .ico (BMP-encoded 16/32/48px + PNG
    256px) following the FileLocksmith pattern.
  • src/modules/CopyAsUNC/CopyAsUNCExt/PowertoyModuleIface DLL loaded by the
    runner. Calls RegisterSparsePackage on enable, deregisters on disable.
  • src/modules/CopyAsUNC/CopyAsUNCLib/ — static lib with settings model/singleton.
  • installer/PowerToysSetupVNext/CopyAsUNC.wxs — WiX installer fragment.

Settings UI changes:

  • EnabledModules.cs — added CopyAsUNC bool property
    ([JsonPropertyName("Copy as UNC")]).
  • PowerPreviewViewModel.cs — added IsCopyAsUNCEnabled backed by
    GeneralSettings.Enabled.CopyAsUNC, sends OutGoingGeneralSettings IPC.
  • PowerPreviewPage.xaml — added Shell Integration SettingsGroup with toggle.
  • No separate settings file, ViewModel page, or navigation entry — the on/off
    toggle is the only control needed.

Questions:

  1. AppxManifest.xml uses Executable="PowerToys.exe" as a placeholder — Copy
    as UNC has no UI executable. Is this the correct value, or should it differ?
  2. GPO support is currently stubbed as GpoRuleConfigured.Unavailable. Happy to
    add a proper gpo.h + GPOWrapper entry if the team points to the right
    pattern.
  3. A build post-build step signs the MSIX with a local self-signed cert so I could get
    it to run, should be removed, guidance required.
  4. Added custom Icon on context menu, this would need changing to follow Win 11
    design guidelines.
  5. In the File Explorer Pane, the toggle enable is at the bottom of the page, not sure how discoverable
    this is, maybe it would be better at the top, suggestions welcome.

Validation Steps Performed

  • Enabled the toggle in Settings → File Explorer Add-ons → Shell Integration.
  • Right-clicked a file on a mapped network drive (e.g. Z:\folder\file.txt) in
    Windows 11 File Explorer.
  • Confirmed "Copy as UNC path" appears in the modern context menu with the correct
    icon.
  • Confirmed clipboard contains the resolved UNC path
    (e.g. \\server\share\folder\file.txt).
  • Right-clicked a local file — confirmed the menu entry is hidden (drive type ≠
    DRIVE_REMOTE).
  • Disabled the toggle — confirmed the menu entry is hidden entirely.
  • Confirmed CopyAsUNCContextMenu is included in the sparse package uninstall
    cleanup list in CustomAction.cpp.

RamblingGeekUK and others added 9 commits March 8, 2026 09:00
Adds a new PowerToys utility that copies the UNC path of files and
folders on mapped network drives to the clipboard via the shell context
menu. When a user right-clicks a file on a mapped drive, the command
resolves the drive letter to its full UNC path using WNetGetUniversalNameW
and writes it to the clipboard.

Components added:
- CopyAsUNCLib: static lib with settings model and singleton
- CopyAsUNCContextMenu: COM shell extension DLL (IExplorerCommand)
  registered via MSIX sparse package
- CopyAsUNCExt: PowertoyModuleIface DLL loaded by the runner
- Settings UI: Library types, ViewModel, XAML page, nav entry,
  localization strings, and serialization context registrations

GPO support is stubbed (returns Unavailable) pending a formal GPO
policy entry.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Remove _enabledGpoRuleConfiguration field that was assigned but never
read (GPO is stubbed to Unavailable; no conditional logic reads the field).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Register CopyAsUNCContextMenu sparse package for removal during
uninstall alongside the other context menu packages.

The DLLs and MSIX are automatically included in the installer via the
existing WinUI3ApplicationsFiles component group.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Drop 'path' from all display strings for a cleaner, shorter name
- Add CopyAsUNC.png to Assets/Settings/Icons/ so the navigation
  item shows the module icon

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Per PowerToys team feedback, Copy as UNC is not a standalone utility.
Instead, integrate it as a 'Shell Integration' section on the
File Explorer Add-ons settings page.

- Remove CopyAsUNCPage, CopyAsUNCViewModel, nav entry, module PNGs
- Remove ModuleType.CopyAsUNC (no longer a top-level module type)
- Add IsCopyAsUNCEnabled property to PowerPreviewViewModel, writing
  to GeneralSettings.Enabled.CopyAsUNC via OutGoingGeneralSettings IPC
- Add 'Shell Integration' SettingsGroup to PowerPreviewPage.xaml
  with a toggle for Copy as UNC
- Replace CopyAsUNC-specific resource strings with
  FileExplorerPreview_ShellIntegration and
  FileExplorerPreview_CopyAsUNC_Enable entries

The C++ module, runner integration, and settings library types are
unchanged — only the Settings UI surface is affected.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The CopyAsUNC module's enable/disable state is held in GeneralSettings,
so no module-specific settings file or types are needed.

Remove CopyAsUNCSettings, CopyAsUNCProperties, CopyAsUNCLocalProperties
and their JsonSerializable registrations.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Convert SVG icon to multi-size ICO (16/32/48/256px) and wire up
the post-build copy step so GetIcon() can locate it at runtime
from WinUI3Apps\Assets\CopyAsUNC\CopyAsUNC.ico.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Regenerated CopyAsUNC.ico with BMP-encoded DIB entries for 16/32/48px
and PNG for 256px. Windows shell requires BMP encoding for small icon
sizes in context menus; PNG-only ICOs fail to render.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- ESRPSigning_core.json: add CopyAsUNCExt.dll, CopyAsUNCContextMenu.dll,
  CopyAsUNCContextMenuPackage.msix for code signing
- CopyAsUNC.wxs: new installer fragment for Assets\CopyAsUNC\ folder
  (mirrors FileLocksmith.wxs pattern)
- Product.wxs: reference CopyAsUNCComponentGroup
- PowerToysInstallerVNext.wixproj: compile CopyAsUNC.wxs, restore .bk on post-build
- generateAllFileComponents.ps1: generate file components for CopyAsUNC assets

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@RamblingGeekUK RamblingGeekUK requested a review from a team as a code owner March 10, 2026 20:28
@michaeljolley michaeljolley changed the title Users/wtt/copy as unc New Shell Extension PowerToy: Copy as UNC Mar 10, 2026
@michaeljolley michaeljolley changed the title New Shell Extension PowerToy: Copy as UNC New Shell Integration PowerToy: Copy as UNC Mar 10, 2026
@github-actions

This comment has been minimized.

@RamblingGeekUK
Copy link
Author

@microsoft-github-policy-service agree

Adds COPYASUNCCONTEXTMENU, COPYASUNCEXT, WNet, and INFOW to the
spell-check expect list. These are preprocessor macro names and
Windows API identifiers flagged as false positives by CI.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@michaeljolley
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@michaeljolley
Copy link
Contributor

@RamblingGeekUK errored with:

C:\a_work\1\s.pipelines\applyXamlStyling.ps1 : XAML Styling is incorrect, please run .\.pipelines\applyXamlStyling.ps1 -Main locally.

RamblingGeekUK and others added 2 commits March 11, 2026 17:52
Run clang-format on CopyAsUNC C++ files and XamlStyler on
PowerPreviewPage.xaml to comply with repo style enforcement rules.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@michaeljolley
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

- Add ConfigureEnabledUtilityCopyAsUNC GPO policy to gpo.h,
  GPOWrapper.h/.idl/.cpp and wire up in PowerToysModule.cpp
- Remove hardcoded self-signed cert signtool post-build step from
  CopyAsUNCContextMenu.vcxproj (CI pipeline handles signing)
- Remove TODO comment from AppxManifest.xml (PowerToys.exe confirmed
  as correct placeholder for modules with no UI executable)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@michaeljolley
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

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.

Copy as UNC

2 participants