[Installer] Upgrade the installer from WiX3 to WiX5 (#40877)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
Background: The current PowerToys installer is built using Wix3, which
has now been deprecated. To improve security, service quality, and
community support, we’re upgrading the installer to Wix5.
Implementation:
Created Wix5-based projects(PowerToysSetupVext and
PowerToysSetupCustomActionsVNext) within the installer while retaining
the existing Wix3 project. Both versions are built to generate separate
installation packages. The Wix3-related code will be removed after
successful release testing confirms no issues.
Special case:
Wix5 has removed the property for 'ShowFilesInUse'. Now, whenever a file
is in use during installation, a FilesInUse pop-upwill automatically
appear asking for the next step. To ensure this doesn't interfere with
scenarios that require silent installation (e.g. Winget method), we’ve
handled it using the bafunction approach.
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
- [ ] Closes: #xxx
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx
<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments
<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
---------
Co-authored-by: Jerry Xu <n.xu@outlook.com>
Co-authored-by: Kai Tao <69313318+vanzue@users.noreply.github.com>
Co-authored-by: leileizhang <leilzh@microsoft.com>
Co-authored-by: Kai Tao (from Dev Box) <kaitao@microsoft.com>
Co-authored-by: vanzue <vanzue@outlook.com>
2025-08-25 18:39:11 +08:00
|
|
|
#include "pch.h"
|
|
|
|
|
#include "resource.h"
|
|
|
|
|
#include "RcResource.h"
|
|
|
|
|
#include <ProjectTelemetry.h>
|
|
|
|
|
#include <spdlog/sinks/base_sink.h>
|
Initial DSC v3 support for PowerToys (#41132)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
Tasks checklist
- [X] Implement DSC infra in PowerToys
- [X] Implement Settings DSC resource
- [X] Implement Get, Set, Test, Export, Schema
- [X] Generate manifest (DSC resource JSON)
- [X] Added Unit Tests
- [x] Add `NJsonSchema` v11.4.0 to the stream
- [x] Package the manifest files so dsc.exe can discover them
- [x] Add `PowerToys.DSC.exe` to the PATH (maybe?)
- [x] Add `InstallLocation` in the registry key so `winget configue
export` can export the PowerToys DSC resources
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
- [X] Closes: #37276
- [X] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [X] **Tests:** Added/updated and all pass
- [X] **Localization:** All end-user-facing strings can be localized
- [x] **Dev docs:** Added/updated
- [x] **New binaries:** Added on the required places
- [x] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [x] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [x] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [x] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [x] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx
<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments
<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
---------
Co-authored-by: vanzue <vanzue@outlook.com>
Co-authored-by: Kai Tao (from Dev Box) <kaitao@microsoft.com>
Co-authored-by: Leilei Zhang <leilzh@microsoft.com>
2025-09-28 00:12:51 -07:00
|
|
|
#include <filesystem>
|
Remove unused dependencies and shrink installer size (#47233)
## Summary of the Pull Request
Two related installer changes to (1) eliminate genuinely-unused
dependencies and (2) deduplicate shared WinAppSDK files between
`<install>\` and `<install>\WinUI3Apps\` to shrink the installer
download.
### 1. Remove unused dependencies (~11 MB savings per output location)
- **System.Data.SqlClient**: Removed from MouseWithoutBorders projects
and the central `Directory.Packages.props` pin. It was a transitive
dependency of `Microsoft.Windows.Compatibility` but PowerToys has zero
SQL database usage.
- **Unused `using` import**: Removed `using
System.ServiceModel.Channels` from MouseWithoutBorders `Program.cs` (no
WCF usage).
- **MFC / C++ AMP / OpenMP DLLs**: Added `RemoveUnusedVCRuntimeDlls`
target in `Directory.Build.targets` to clean up `mfc140*`, `mfcm140*`,
`vcamp140*`, and `vcomp140*` DLLs that leak from the VC++
Redistributable tree but are not imported by any PowerToys binary
(verified with `dumpbin /dependents` across all installed binaries).
Also excluded MFC DLLs from installer file collection.
### 2. WinAppSDK file deduplication (build-time only; install-time uses
copy)
**Background**: The `WinUI3Apps` subfolder must remain a real directory
because MSIX sparse package registration applies DACL changes to the
`ExternalLocation` folder (PR #47177). Flattening is not viable.
**Build-time** (`generateAllFileComponents.ps1`): computes the SHA256
intersection of root and `WinUI3Apps` files, and for each file that is
also present in the BaseApplications WXS file list, removes the
duplicate from the WinUI3Apps WXS component list and writes its name to
a `hardlinks.txt` manifest. The BaseApplications cross-check ensures we
never deduplicate a file the MSI does not actually deploy at the install
root, which would otherwise leave both copies missing post-install. The
manifest is written as UTF-8 without BOM (via
`[System.IO.File]::WriteAllLines` with `UTF8Encoding($false)`) so its
encoding is identical regardless of the build host's PowerShell version.
This step produces the **MSI download-size win** (~97 MB smaller cab;
LZX:21 was already deduplicating most byte-identical content
automatically inside the cab).
**Install-time** (`CreateWinAppSDKHardlinksCA` custom action):
- Reads `hardlinks.txt` after `InstallFiles` as a raw byte stream and
converts each line to a `std::wstring` via `MultiByteToWideChar(CP_UTF8,
MB_ERR_INVALID_CHARS, ...)`. Avoids `std::wifstream`'s ANSI-codepage
codecvt so non-ASCII paths can never be silently mangled.
- For each entry, computes `(installDir / fileName).lexically_normal()`
and `(winui3Dir / fileName).lexically_normal()`, then verifies via
`std::mismatch` that each resolved path is still rooted at its
respective folder. Manifest entries containing `..`, absolute paths, or
alternate-stream syntax are logged and skipped.
- Materialises each validated entry from `<install>\<name>` into
`<install>\WinUI3Apps\<name>` via `fs::copy_file` (overwrite_existing).
- Reports the per-file copy / failure counts to the install log. If
every entry failed (`created == 0 && failed > 0`), the CA escalates to
`E_FAIL` so the install does not silently succeed with an unusable
WinUI3Apps tree.
`DeleteWinAppSDKHardlinksCA` removes the materialised copies before
`RemoveFiles` on uninstall, using the same UTF-8 reader and per-entry
containment check.
**WiX sequencing**: `CreateWinAppSDKHardlinks` runs
`After="InstallFiles"` with `Condition="NOT Installed OR
WIX_UPGRADE_DETECTED OR REINSTALL"` so a `msiexec /fa` repair refreshes
the deduplicated copies (otherwise `RemoveFiles` would orphan them).
#### Why copy and not hard-link
A hard-linked variant of this CA was originally proposed but caused a
Monaco preview-handler regression. Hard-links share an NTFS inode (and
therefore one DACL) between `<install>\<file>` and
`<install>\WinUI3Apps\<file>`. The MSIX sparse-package registrations for
PowerRename / ImageResizer / FileLocksmith / NewPlus run after the dedup
CA and propagate the `WinUI3Apps` parent's rich DACL (Capability SID, 5×
Package SIDs, 5× conditional SYSAPPID ACE, RC SID) onto the shared
inode. The root path then also exposes the rich DACL, which trips a
kernel "stricter access evaluation" path that blocks the LOW-IL
`prevhost.exe` from `LoadLibrary`-ing `hostfxr.dll` (and the rest of the
.NET runtime), turning the Monaco preview pane blank for `.json` / `.md`
/ `.cs` / `.xaml` / `.svg` / `.xml` files.
`fs::copy_file` creates a **fresh inode** for the WinUI3Apps copy. The
root inode keeps its simple DACL (`SY:F + BA:F + owner:F` + inherited
`BU:RX`) so LOW-IL `prevhost.exe` can still load it — Monaco preview
works. The WinUI3Apps copy inherits the WinUI3Apps parent's rich DACL
via normal NTFS inheritance (matches 0.99.1 behaviour exactly) — MSIX
context-menu shells continue to work.
#### Trade-off
| Metric | Hard-link variant (rejected) | This PR (file copy) | 0.99.1
(no dedup) |
|---|---|---|---|
| MSI size | ~296 MB | ~296 MB | ~393 MB |
| On-disk after install | ~2,475 MB | ~2,772 MB | ~2,772 MB |
| DACL contamination risk | YES (broke Monaco) | NO | NO |
The on-disk savings (~297 MB) are given up in exchange for eliminating
the DACL contamination risk; the **installer download savings (~97 MB)**
are preserved by the build-time WiX/cab dedup.
#### Edge cases handled
- Empty duplicate list: `hardlinks.txt` always written, CA handles
empty.
- All files duplicated: `Generate-FileComponents` returns early for
empty list.
- File stripped from BaseApplications by an earlier build step:
BaseApplications cross-check skips it during dedup so neither copy goes
missing.
- Manifest entry escapes install root (`..`, absolute path): rejected
per-entry, install continues.
- Manifest line is non-UTF-8: rejected per-entry, install continues.
- Source missing at install time: per-entry skip, install continues.
- All copies fail: install aborts loudly via `E_FAIL` (catastrophic-case
escalation).
- Upgrade or `msiexec /fa` repair: CA fires (`NOT Installed OR
WIX_UPGRADE_DETECTED OR REINSTALL`).
**MSI repair risk**: Burn bundle uses `SuppressRepair=yes` and
`MajorUpgrade` (full uninstall + reinstall) for all version upgrades, so
the standard upgrade path is unaffected. The `OR REINSTALL` clause
covers power users running `msiexec /fa` directly.
## PR Checklist
- [x] **Communication:** Discussed approach via PRs #46866, #47177,
#46745
- [ ] **Tests:** Installer infrastructure only — no runtime behaviour
changes
- [ ] **Localization:** N/A
- [ ] **Dev docs:** N/A
- [ ] **New binaries:** N/A
## Detailed Description of the Pull Request / Additional comments
Based on the approach from PR #46745 by @yeelam-gordon, rebased onto
latest main and switched from hard-links to file copies after the DACL
contamination root cause was identified. Hardening (UTF-8 read, path
containment, catastrophic-case escalation, REINSTALL repair,
BaseApplications-filtered dedup) added in response to review feedback.
These changes are purely build/installer infrastructure — no runtime
behaviour changes to any PowerToys module.
## Validation Steps Performed
Validated on a 0.99.4 / 0.99.5 local install (per-user
`%LocalAppData%\PowerToys`):
- ✅ `dumpbin /dependents` across the installed PowerToys tree confirmed
zero binaries import `mfc140*`, `mfcm140*`, `vcamp140*`, or `vcomp140*`
— the cleanup target removes ~11 MB of genuinely unused VC runtime DLLs.
- ✅ `System.Data.SqlClient` has zero call-sites in PowerToys source.
- ✅ Local installer build produces a 296 MB MSI (down from 393 MB
pre-dedup, ~97 MB cab savings purely from the build-time WiX dedup).
- ✅ MSI table inspection (`wix msi decompile`) confirms the deferred CAs
are present (`CreateWinAppSDKHardlinks`, `DeleteWinAppSDKHardlinks`) and
the `hardlinks.txt` File row is registered.
- ✅ MSI table inspection confirms .NET runtime DLLs (`hostfxr.dll`,
`coreclr.dll`, `hostpolicy.dll`, `clretwrc.dll`, `Accessibility.dll`,
`backup_restore_settings.json`) appear ONLY in
`BaseApplicationsFiles_File_*`, NOT in `WinUI3ApplicationsFiles_File_*`
— proving the build-time dedup worked.
- ✅ Post-install verification: deduplicated files materialised at both
root and WinUI3Apps with byte-identical SHA256 hashes, and `fsutil
hardlink list` returns link-count == 1 for each — proving the
install-time copy approach worked, not hard-link.
- ✅ DACL on root .NET runtime DLLs is clean: no Package SID, no
Capability SID, no SYSAPPID conditional ACE, no `ALL APPLICATION
PACKAGES` ACE — Monaco preview load path is safe.
- ✅ DACL on WinUI3Apps copies has the rich MSIX inheritance —
context-menu shells continue to work (matches 0.99.1).
- ✅ All four MSIX sparse packages (PowerRename, ImageResizer,
FileLocksmith, NewPlus) registered after install.
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-15 17:15:11 +08:00
|
|
|
#include <fstream>
|
2025-11-14 16:15:15 +08:00
|
|
|
#include <string_view>
|
[Installer] Upgrade the installer from WiX3 to WiX5 (#40877)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
Background: The current PowerToys installer is built using Wix3, which
has now been deprecated. To improve security, service quality, and
community support, we’re upgrading the installer to Wix5.
Implementation:
Created Wix5-based projects(PowerToysSetupVext and
PowerToysSetupCustomActionsVNext) within the installer while retaining
the existing Wix3 project. Both versions are built to generate separate
installation packages. The Wix3-related code will be removed after
successful release testing confirms no issues.
Special case:
Wix5 has removed the property for 'ShowFilesInUse'. Now, whenever a file
is in use during installation, a FilesInUse pop-upwill automatically
appear asking for the next step. To ensure this doesn't interfere with
scenarios that require silent installation (e.g. Winget method), we’ve
handled it using the bafunction approach.
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
- [ ] Closes: #xxx
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx
<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments
<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
---------
Co-authored-by: Jerry Xu <n.xu@outlook.com>
Co-authored-by: Kai Tao <69313318+vanzue@users.noreply.github.com>
Co-authored-by: leileizhang <leilzh@microsoft.com>
Co-authored-by: Kai Tao (from Dev Box) <kaitao@microsoft.com>
Co-authored-by: vanzue <vanzue@outlook.com>
2025-08-25 18:39:11 +08:00
|
|
|
|
|
|
|
|
#include "../../src/common/logger/logger.h"
|
|
|
|
|
#include "../../src/common/utils/gpo.h"
|
|
|
|
|
#include "../../src/common/utils/MsiUtils.h"
|
|
|
|
|
#include "../../src/common/utils/modulesRegistry.h"
|
|
|
|
|
#include "../../src/common/updating/installer.h"
|
|
|
|
|
#include "../../src/common/version/version.h"
|
|
|
|
|
#include "../../src/common/Telemetry/EtwTrace/EtwTrace.h"
|
|
|
|
|
#include "../../src/common/utils/package.h"
|
|
|
|
|
#include "../../src/common/utils/clean_video_conference.h"
|
|
|
|
|
|
|
|
|
|
#include <winrt/Windows.ApplicationModel.h>
|
|
|
|
|
#include <winrt/Windows.Foundation.h>
|
|
|
|
|
#include <winrt/Windows.Management.Deployment.h>
|
|
|
|
|
#include <winrt/Windows.Security.Credentials.h>
|
|
|
|
|
|
|
|
|
|
#include <wtsapi32.h>
|
|
|
|
|
#include <processthreadsapi.h>
|
|
|
|
|
#include <UserEnv.h>
|
|
|
|
|
#include <winnt.h>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
HINSTANCE DLL_HANDLE = nullptr;
|
|
|
|
|
|
|
|
|
|
TRACELOGGING_DEFINE_PROVIDER(
|
|
|
|
|
g_hProvider,
|
|
|
|
|
"Microsoft.PowerToys",
|
|
|
|
|
// {38e8889b-9731-53f5-e901-e8a7c1753074}
|
|
|
|
|
(0x38e8889b, 0x9731, 0x53f5, 0xe9, 0x01, 0xe8, 0xa7, 0xc1, 0x75, 0x30, 0x74),
|
|
|
|
|
TraceLoggingOptionProjectTelemetry());
|
|
|
|
|
|
|
|
|
|
const DWORD USERNAME_DOMAIN_LEN = DNLEN + UNLEN + 2; // Domain Name + '\' + User Name + '\0'
|
|
|
|
|
const DWORD USERNAME_LEN = UNLEN + 1; // User Name + '\0'
|
|
|
|
|
|
|
|
|
|
static const wchar_t *POWERTOYS_EXE_COMPONENT = L"{A2C66D91-3485-4D00-B04D-91844E6B345B}";
|
|
|
|
|
static const wchar_t *POWERTOYS_UPGRADE_CODE = L"{42B84BF7-5FBF-473B-9C8B-049DC16F7708}";
|
|
|
|
|
|
|
|
|
|
constexpr inline const wchar_t *DataDiagnosticsRegKey = L"Software\\Classes\\PowerToys";
|
|
|
|
|
constexpr inline const wchar_t *DataDiagnosticsRegValueName = L"AllowDataDiagnostics";
|
|
|
|
|
|
|
|
|
|
#define TraceLoggingWriteWrapper(provider, eventName, ...) \
|
|
|
|
|
if (isDataDiagnosticEnabled()) \
|
|
|
|
|
{ \
|
|
|
|
|
trace.UpdateState(true); \
|
|
|
|
|
TraceLoggingWrite(provider, eventName, __VA_ARGS__); \
|
|
|
|
|
trace.Flush(); \
|
|
|
|
|
trace.UpdateState(false); \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Shared::Trace::ETWTrace trace{L"PowerToys_Installer"};
|
|
|
|
|
|
|
|
|
|
inline bool isDataDiagnosticEnabled()
|
|
|
|
|
{
|
|
|
|
|
HKEY key{};
|
|
|
|
|
if (RegOpenKeyExW(HKEY_CURRENT_USER,
|
|
|
|
|
DataDiagnosticsRegKey,
|
|
|
|
|
0,
|
|
|
|
|
KEY_READ,
|
|
|
|
|
&key) != ERROR_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DWORD isDataDiagnosticsEnabled = 0;
|
|
|
|
|
DWORD size = sizeof(isDataDiagnosticsEnabled);
|
|
|
|
|
|
|
|
|
|
if (RegGetValueW(
|
|
|
|
|
HKEY_CURRENT_USER,
|
|
|
|
|
DataDiagnosticsRegKey,
|
|
|
|
|
DataDiagnosticsRegValueName,
|
|
|
|
|
RRF_RT_REG_DWORD,
|
|
|
|
|
nullptr,
|
|
|
|
|
&isDataDiagnosticsEnabled,
|
|
|
|
|
&size) != ERROR_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
RegCloseKey(key);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
RegCloseKey(key);
|
|
|
|
|
|
|
|
|
|
return isDataDiagnosticsEnabled == 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HRESULT getInstallFolder(MSIHANDLE hInstall, std::wstring &installationDir)
|
|
|
|
|
{
|
|
|
|
|
DWORD len = 0;
|
|
|
|
|
wchar_t _[1];
|
|
|
|
|
MsiGetPropertyW(hInstall, L"CustomActionData", _, &len);
|
|
|
|
|
len += 1;
|
|
|
|
|
installationDir.resize(len);
|
|
|
|
|
HRESULT hr = MsiGetPropertyW(hInstall, L"CustomActionData", installationDir.data(), &len);
|
|
|
|
|
if (installationDir.length())
|
|
|
|
|
{
|
|
|
|
|
installationDir.resize(installationDir.length() - 1);
|
|
|
|
|
}
|
|
|
|
|
ExitOnFailure(hr, "Failed to get INSTALLFOLDER property.");
|
|
|
|
|
LExit:
|
|
|
|
|
return hr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOL IsLocalSystem()
|
|
|
|
|
{
|
|
|
|
|
HANDLE hToken;
|
|
|
|
|
UCHAR bTokenUser[sizeof(TOKEN_USER) + 8 + 4 * SID_MAX_SUB_AUTHORITIES];
|
|
|
|
|
PTOKEN_USER pTokenUser = (PTOKEN_USER)bTokenUser;
|
|
|
|
|
ULONG cbTokenUser;
|
|
|
|
|
SID_IDENTIFIER_AUTHORITY siaNT = SECURITY_NT_AUTHORITY;
|
|
|
|
|
PSID pSystemSid;
|
|
|
|
|
BOOL bSystem;
|
|
|
|
|
|
|
|
|
|
// open process token
|
|
|
|
|
if (!OpenProcessToken(GetCurrentProcess(),
|
|
|
|
|
TOKEN_QUERY,
|
|
|
|
|
&hToken))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
// retrieve user SID
|
|
|
|
|
if (!GetTokenInformation(hToken, TokenUser, pTokenUser,
|
|
|
|
|
sizeof(bTokenUser), &cbTokenUser))
|
|
|
|
|
{
|
|
|
|
|
CloseHandle(hToken);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CloseHandle(hToken);
|
|
|
|
|
|
|
|
|
|
// allocate LocalSystem well-known SID
|
|
|
|
|
if (!AllocateAndInitializeSid(&siaNT, 1, SECURITY_LOCAL_SYSTEM_RID,
|
|
|
|
|
0, 0, 0, 0, 0, 0, 0, &pSystemSid))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
// compare the user SID from the token with the LocalSystem SID
|
|
|
|
|
bSystem = EqualSid(pTokenUser->User.Sid, pSystemSid);
|
|
|
|
|
|
|
|
|
|
FreeSid(pSystemSid);
|
|
|
|
|
|
|
|
|
|
return bSystem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOL ImpersonateLoggedInUserAndDoSomething(std::function<bool(HANDLE userToken)> action)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
HANDLE hUserToken = NULL;
|
|
|
|
|
DWORD dwSessionId;
|
|
|
|
|
ProcessIdToSessionId(GetCurrentProcessId(), &dwSessionId);
|
|
|
|
|
auto rv = WTSQueryUserToken(dwSessionId, &hUserToken);
|
|
|
|
|
|
|
|
|
|
if (rv == 0)
|
|
|
|
|
{
|
|
|
|
|
hr = E_ABORT;
|
|
|
|
|
ExitOnFailure(hr, "Failed to query user token");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HANDLE hUserTokenDup;
|
|
|
|
|
if (DuplicateTokenEx(hUserToken, TOKEN_ALL_ACCESS, NULL, SECURITY_IMPERSONATION_LEVEL::SecurityImpersonation, TOKEN_TYPE::TokenPrimary, &hUserTokenDup) == 0)
|
|
|
|
|
{
|
|
|
|
|
CloseHandle(hUserToken);
|
|
|
|
|
CloseHandle(hUserTokenDup);
|
|
|
|
|
hr = E_ABORT;
|
|
|
|
|
ExitOnFailure(hr, "Failed to duplicate user token");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ImpersonateLoggedOnUser(hUserTokenDup))
|
|
|
|
|
{
|
|
|
|
|
if (!action(hUserTokenDup))
|
|
|
|
|
{
|
|
|
|
|
hr = E_ABORT;
|
|
|
|
|
ExitOnFailure(hr, "Failed to execute action");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RevertToSelf();
|
|
|
|
|
CloseHandle(hUserToken);
|
|
|
|
|
CloseHandle(hUserTokenDup);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
hr = E_ABORT;
|
|
|
|
|
ExitOnFailure(hr, "Failed to duplicate user token");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LExit:
|
|
|
|
|
return SUCCEEDED(hr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static std::filesystem::path GetUserPowerShellModulesPath()
|
|
|
|
|
{
|
|
|
|
|
PWSTR myDocumentsBlockPtr;
|
|
|
|
|
|
|
|
|
|
if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_Documents, 0, NULL, &myDocumentsBlockPtr)))
|
|
|
|
|
{
|
|
|
|
|
const std::wstring myDocuments{myDocumentsBlockPtr};
|
|
|
|
|
CoTaskMemFree(myDocumentsBlockPtr);
|
|
|
|
|
return std::filesystem::path(myDocuments) / "PowerShell" / "Modules";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CoTaskMemFree(myDocumentsBlockPtr);
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UINT __stdcall LaunchPowerToysCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
std::wstring installationFolder, path, args;
|
|
|
|
|
std::wstring commandLine;
|
|
|
|
|
|
|
|
|
|
hr = WcaInitialize(hInstall, "LaunchPowerToys");
|
|
|
|
|
ExitOnFailure(hr, "Failed to initialize");
|
|
|
|
|
hr = getInstallFolder(hInstall, installationFolder);
|
|
|
|
|
ExitOnFailure(hr, "Failed to get installFolder.");
|
|
|
|
|
|
|
|
|
|
path = installationFolder;
|
|
|
|
|
path += L"\\PowerToys.exe";
|
|
|
|
|
|
|
|
|
|
args = L"--dont-elevate";
|
|
|
|
|
|
|
|
|
|
commandLine = L"\"" + path + L"\" ";
|
|
|
|
|
commandLine += args;
|
|
|
|
|
|
|
|
|
|
BOOL isSystemUser = IsLocalSystem();
|
|
|
|
|
|
|
|
|
|
if (isSystemUser)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
auto action = [&commandLine](HANDLE userToken)
|
|
|
|
|
{
|
Initial DSC v3 support for PowerToys (#41132)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
Tasks checklist
- [X] Implement DSC infra in PowerToys
- [X] Implement Settings DSC resource
- [X] Implement Get, Set, Test, Export, Schema
- [X] Generate manifest (DSC resource JSON)
- [X] Added Unit Tests
- [x] Add `NJsonSchema` v11.4.0 to the stream
- [x] Package the manifest files so dsc.exe can discover them
- [x] Add `PowerToys.DSC.exe` to the PATH (maybe?)
- [x] Add `InstallLocation` in the registry key so `winget configue
export` can export the PowerToys DSC resources
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
- [X] Closes: #37276
- [X] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [X] **Tests:** Added/updated and all pass
- [X] **Localization:** All end-user-facing strings can be localized
- [x] **Dev docs:** Added/updated
- [x] **New binaries:** Added on the required places
- [x] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [x] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [x] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [x] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [x] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx
<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments
<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
---------
Co-authored-by: vanzue <vanzue@outlook.com>
Co-authored-by: Kai Tao (from Dev Box) <kaitao@microsoft.com>
Co-authored-by: Leilei Zhang <leilzh@microsoft.com>
2025-09-28 00:12:51 -07:00
|
|
|
STARTUPINFO startupInfo = { 0 };
|
|
|
|
|
startupInfo.cb = sizeof(STARTUPINFO);
|
|
|
|
|
startupInfo.wShowWindow = SW_SHOWNORMAL;
|
[Installer] Upgrade the installer from WiX3 to WiX5 (#40877)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
Background: The current PowerToys installer is built using Wix3, which
has now been deprecated. To improve security, service quality, and
community support, we’re upgrading the installer to Wix5.
Implementation:
Created Wix5-based projects(PowerToysSetupVext and
PowerToysSetupCustomActionsVNext) within the installer while retaining
the existing Wix3 project. Both versions are built to generate separate
installation packages. The Wix3-related code will be removed after
successful release testing confirms no issues.
Special case:
Wix5 has removed the property for 'ShowFilesInUse'. Now, whenever a file
is in use during installation, a FilesInUse pop-upwill automatically
appear asking for the next step. To ensure this doesn't interfere with
scenarios that require silent installation (e.g. Winget method), we’ve
handled it using the bafunction approach.
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
- [ ] Closes: #xxx
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx
<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments
<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
---------
Co-authored-by: Jerry Xu <n.xu@outlook.com>
Co-authored-by: Kai Tao <69313318+vanzue@users.noreply.github.com>
Co-authored-by: leileizhang <leilzh@microsoft.com>
Co-authored-by: Kai Tao (from Dev Box) <kaitao@microsoft.com>
Co-authored-by: vanzue <vanzue@outlook.com>
2025-08-25 18:39:11 +08:00
|
|
|
PROCESS_INFORMATION processInformation;
|
|
|
|
|
|
|
|
|
|
PVOID lpEnvironment = NULL;
|
|
|
|
|
CreateEnvironmentBlock(&lpEnvironment, userToken, FALSE);
|
|
|
|
|
|
|
|
|
|
CreateProcessAsUser(
|
|
|
|
|
userToken,
|
|
|
|
|
NULL,
|
|
|
|
|
commandLine.data(),
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
FALSE,
|
|
|
|
|
CREATE_DEFAULT_ERROR_MODE | CREATE_UNICODE_ENVIRONMENT,
|
|
|
|
|
lpEnvironment,
|
|
|
|
|
NULL,
|
|
|
|
|
&startupInfo,
|
|
|
|
|
&processInformation);
|
|
|
|
|
|
|
|
|
|
if (!CloseHandle(processInformation.hProcess))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!CloseHandle(processInformation.hThread))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!ImpersonateLoggedInUserAndDoSomething(action))
|
|
|
|
|
{
|
|
|
|
|
hr = E_ABORT;
|
|
|
|
|
ExitOnFailure(hr, "ImpersonateLoggedInUserAndDoSomething failed");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
Initial DSC v3 support for PowerToys (#41132)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
Tasks checklist
- [X] Implement DSC infra in PowerToys
- [X] Implement Settings DSC resource
- [X] Implement Get, Set, Test, Export, Schema
- [X] Generate manifest (DSC resource JSON)
- [X] Added Unit Tests
- [x] Add `NJsonSchema` v11.4.0 to the stream
- [x] Package the manifest files so dsc.exe can discover them
- [x] Add `PowerToys.DSC.exe` to the PATH (maybe?)
- [x] Add `InstallLocation` in the registry key so `winget configue
export` can export the PowerToys DSC resources
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
- [X] Closes: #37276
- [X] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [X] **Tests:** Added/updated and all pass
- [X] **Localization:** All end-user-facing strings can be localized
- [x] **Dev docs:** Added/updated
- [x] **New binaries:** Added on the required places
- [x] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [x] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [x] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [x] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [x] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx
<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments
<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
---------
Co-authored-by: vanzue <vanzue@outlook.com>
Co-authored-by: Kai Tao (from Dev Box) <kaitao@microsoft.com>
Co-authored-by: Leilei Zhang <leilzh@microsoft.com>
2025-09-28 00:12:51 -07:00
|
|
|
STARTUPINFO startupInfo = { 0 };
|
|
|
|
|
startupInfo.cb = sizeof(STARTUPINFO);
|
|
|
|
|
startupInfo.wShowWindow = SW_SHOWNORMAL;
|
[Installer] Upgrade the installer from WiX3 to WiX5 (#40877)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
Background: The current PowerToys installer is built using Wix3, which
has now been deprecated. To improve security, service quality, and
community support, we’re upgrading the installer to Wix5.
Implementation:
Created Wix5-based projects(PowerToysSetupVext and
PowerToysSetupCustomActionsVNext) within the installer while retaining
the existing Wix3 project. Both versions are built to generate separate
installation packages. The Wix3-related code will be removed after
successful release testing confirms no issues.
Special case:
Wix5 has removed the property for 'ShowFilesInUse'. Now, whenever a file
is in use during installation, a FilesInUse pop-upwill automatically
appear asking for the next step. To ensure this doesn't interfere with
scenarios that require silent installation (e.g. Winget method), we’ve
handled it using the bafunction approach.
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
- [ ] Closes: #xxx
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx
<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments
<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
---------
Co-authored-by: Jerry Xu <n.xu@outlook.com>
Co-authored-by: Kai Tao <69313318+vanzue@users.noreply.github.com>
Co-authored-by: leileizhang <leilzh@microsoft.com>
Co-authored-by: Kai Tao (from Dev Box) <kaitao@microsoft.com>
Co-authored-by: vanzue <vanzue@outlook.com>
2025-08-25 18:39:11 +08:00
|
|
|
|
|
|
|
|
PROCESS_INFORMATION processInformation;
|
|
|
|
|
|
|
|
|
|
// Start the resizer
|
|
|
|
|
CreateProcess(
|
|
|
|
|
NULL,
|
|
|
|
|
commandLine.data(),
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
TRUE,
|
|
|
|
|
0,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
&startupInfo,
|
|
|
|
|
&processInformation);
|
|
|
|
|
|
|
|
|
|
if (!CloseHandle(processInformation.hProcess))
|
|
|
|
|
{
|
|
|
|
|
hr = E_ABORT;
|
|
|
|
|
ExitOnFailure(hr, "Failed to close process handle");
|
|
|
|
|
}
|
|
|
|
|
if (!CloseHandle(processInformation.hThread))
|
|
|
|
|
{
|
|
|
|
|
hr = E_ABORT;
|
|
|
|
|
ExitOnFailure(hr, "Failed to close thread handle");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LExit:
|
|
|
|
|
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UINT __stdcall CheckGPOCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
|
|
hr = WcaInitialize(hInstall, "CheckGPOCA");
|
|
|
|
|
ExitOnFailure(hr, "Failed to initialize");
|
|
|
|
|
|
|
|
|
|
LPWSTR currentScope = nullptr;
|
|
|
|
|
hr = WcaGetProperty(L"InstallScope", ¤tScope);
|
|
|
|
|
|
|
|
|
|
if (std::wstring{currentScope} == L"perUser")
|
|
|
|
|
{
|
|
|
|
|
if (powertoys_gpo::getDisablePerUserInstallationValue() == powertoys_gpo::gpo_rule_configured_enabled)
|
|
|
|
|
{
|
|
|
|
|
PMSIHANDLE hRecord = MsiCreateRecord(0);
|
|
|
|
|
MsiRecordSetString(hRecord, 0, TEXT("The system administrator has disabled per-user installation."));
|
|
|
|
|
MsiProcessMessage(hInstall, static_cast<INSTALLMESSAGE>(INSTALLMESSAGE_ERROR + MB_OK), hRecord);
|
|
|
|
|
hr = E_ABORT;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LExit:
|
|
|
|
|
UINT er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We've deprecated Video Conference Mute. This Custom Action cleans up any stray registry entry for the driver dll.
|
|
|
|
|
UINT __stdcall CleanVideoConferenceRegistryCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
hr = WcaInitialize(hInstall, "CleanVideoConferenceRegistry");
|
|
|
|
|
ExitOnFailure(hr, "Failed to initialize");
|
|
|
|
|
clean_video_conference();
|
|
|
|
|
LExit:
|
|
|
|
|
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UINT __stdcall ApplyModulesRegistryChangeSetsCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
std::wstring installationFolder;
|
|
|
|
|
bool failedToApply = false;
|
|
|
|
|
|
|
|
|
|
hr = WcaInitialize(hInstall, "ApplyModulesRegistryChangeSets");
|
|
|
|
|
ExitOnFailure(hr, "Failed to initialize");
|
|
|
|
|
hr = getInstallFolder(hInstall, installationFolder);
|
|
|
|
|
ExitOnFailure(hr, "Failed to get installFolder.");
|
|
|
|
|
|
|
|
|
|
for (const auto &changeSet : getAllOnByDefaultModulesChangeSets(installationFolder))
|
|
|
|
|
{
|
|
|
|
|
if (!changeSet.apply())
|
|
|
|
|
{
|
|
|
|
|
Logger::error(L"Couldn't apply registry changeSet");
|
|
|
|
|
failedToApply = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!failedToApply)
|
|
|
|
|
{
|
|
|
|
|
Logger::info(L"All registry changeSets applied successfully");
|
|
|
|
|
}
|
|
|
|
|
LExit:
|
|
|
|
|
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UINT __stdcall UnApplyModulesRegistryChangeSetsCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
std::wstring installationFolder;
|
|
|
|
|
|
|
|
|
|
hr = WcaInitialize(hInstall, "UndoModulesRegistryChangeSets"); // original func name is too long
|
|
|
|
|
ExitOnFailure(hr, "Failed to initialize");
|
|
|
|
|
hr = getInstallFolder(hInstall, installationFolder);
|
|
|
|
|
ExitOnFailure(hr, "Failed to get installFolder.");
|
|
|
|
|
for (const auto &changeSet : getAllModulesChangeSets(installationFolder))
|
|
|
|
|
{
|
|
|
|
|
changeSet.unApply();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);
|
|
|
|
|
|
|
|
|
|
ExitOnFailure(hr, "Failed to extract msix");
|
|
|
|
|
|
|
|
|
|
LExit:
|
|
|
|
|
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const wchar_t *DSC_CONFIGURE_PSD1_NAME = L"Microsoft.PowerToys.Configure.psd1";
|
|
|
|
|
const wchar_t *DSC_CONFIGURE_PSM1_NAME = L"Microsoft.PowerToys.Configure.psm1";
|
|
|
|
|
|
|
|
|
|
UINT __stdcall InstallDSCModuleCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
std::wstring installationFolder;
|
|
|
|
|
|
|
|
|
|
hr = WcaInitialize(hInstall, "InstallDSCModuleCA");
|
|
|
|
|
ExitOnFailure(hr, "Failed to initialize");
|
|
|
|
|
|
|
|
|
|
hr = getInstallFolder(hInstall, installationFolder);
|
|
|
|
|
ExitOnFailure(hr, "Failed to get installFolder.");
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
const auto baseModulesPath = GetUserPowerShellModulesPath();
|
|
|
|
|
if (baseModulesPath.empty())
|
|
|
|
|
{
|
|
|
|
|
hr = E_FAIL;
|
|
|
|
|
ExitOnFailure(hr, "Unable to determine Powershell modules path");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const auto modulesPath = baseModulesPath / L"Microsoft.PowerToys.Configure" / (get_product_version(false) + L".0");
|
|
|
|
|
|
|
|
|
|
std::error_code errorCode;
|
Initial DSC v3 support for PowerToys (#41132)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
Tasks checklist
- [X] Implement DSC infra in PowerToys
- [X] Implement Settings DSC resource
- [X] Implement Get, Set, Test, Export, Schema
- [X] Generate manifest (DSC resource JSON)
- [X] Added Unit Tests
- [x] Add `NJsonSchema` v11.4.0 to the stream
- [x] Package the manifest files so dsc.exe can discover them
- [x] Add `PowerToys.DSC.exe` to the PATH (maybe?)
- [x] Add `InstallLocation` in the registry key so `winget configue
export` can export the PowerToys DSC resources
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
- [X] Closes: #37276
- [X] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [X] **Tests:** Added/updated and all pass
- [X] **Localization:** All end-user-facing strings can be localized
- [x] **Dev docs:** Added/updated
- [x] **New binaries:** Added on the required places
- [x] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [x] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [x] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [x] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [x] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx
<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments
<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
---------
Co-authored-by: vanzue <vanzue@outlook.com>
Co-authored-by: Kai Tao (from Dev Box) <kaitao@microsoft.com>
Co-authored-by: Leilei Zhang <leilzh@microsoft.com>
2025-09-28 00:12:51 -07:00
|
|
|
std::filesystem::create_directories(modulesPath, errorCode);
|
[Installer] Upgrade the installer from WiX3 to WiX5 (#40877)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
Background: The current PowerToys installer is built using Wix3, which
has now been deprecated. To improve security, service quality, and
community support, we’re upgrading the installer to Wix5.
Implementation:
Created Wix5-based projects(PowerToysSetupVext and
PowerToysSetupCustomActionsVNext) within the installer while retaining
the existing Wix3 project. Both versions are built to generate separate
installation packages. The Wix3-related code will be removed after
successful release testing confirms no issues.
Special case:
Wix5 has removed the property for 'ShowFilesInUse'. Now, whenever a file
is in use during installation, a FilesInUse pop-upwill automatically
appear asking for the next step. To ensure this doesn't interfere with
scenarios that require silent installation (e.g. Winget method), we’ve
handled it using the bafunction approach.
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
- [ ] Closes: #xxx
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx
<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments
<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
---------
Co-authored-by: Jerry Xu <n.xu@outlook.com>
Co-authored-by: Kai Tao <69313318+vanzue@users.noreply.github.com>
Co-authored-by: leileizhang <leilzh@microsoft.com>
Co-authored-by: Kai Tao (from Dev Box) <kaitao@microsoft.com>
Co-authored-by: vanzue <vanzue@outlook.com>
2025-08-25 18:39:11 +08:00
|
|
|
if (errorCode)
|
|
|
|
|
{
|
|
|
|
|
hr = E_FAIL;
|
|
|
|
|
ExitOnFailure(hr, "Unable to create Powershell modules folder");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const auto *filename : {DSC_CONFIGURE_PSD1_NAME, DSC_CONFIGURE_PSM1_NAME})
|
|
|
|
|
{
|
Initial DSC v3 support for PowerToys (#41132)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
Tasks checklist
- [X] Implement DSC infra in PowerToys
- [X] Implement Settings DSC resource
- [X] Implement Get, Set, Test, Export, Schema
- [X] Generate manifest (DSC resource JSON)
- [X] Added Unit Tests
- [x] Add `NJsonSchema` v11.4.0 to the stream
- [x] Package the manifest files so dsc.exe can discover them
- [x] Add `PowerToys.DSC.exe` to the PATH (maybe?)
- [x] Add `InstallLocation` in the registry key so `winget configue
export` can export the PowerToys DSC resources
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
- [X] Closes: #37276
- [X] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [X] **Tests:** Added/updated and all pass
- [X] **Localization:** All end-user-facing strings can be localized
- [x] **Dev docs:** Added/updated
- [x] **New binaries:** Added on the required places
- [x] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [x] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [x] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [x] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [x] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx
<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments
<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
---------
Co-authored-by: vanzue <vanzue@outlook.com>
Co-authored-by: Kai Tao (from Dev Box) <kaitao@microsoft.com>
Co-authored-by: Leilei Zhang <leilzh@microsoft.com>
2025-09-28 00:12:51 -07:00
|
|
|
std::filesystem::copy_file(std::filesystem::path(installationFolder) / "DSCModules" / filename, modulesPath / filename, std::filesystem::copy_options::overwrite_existing, errorCode);
|
[Installer] Upgrade the installer from WiX3 to WiX5 (#40877)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
Background: The current PowerToys installer is built using Wix3, which
has now been deprecated. To improve security, service quality, and
community support, we’re upgrading the installer to Wix5.
Implementation:
Created Wix5-based projects(PowerToysSetupVext and
PowerToysSetupCustomActionsVNext) within the installer while retaining
the existing Wix3 project. Both versions are built to generate separate
installation packages. The Wix3-related code will be removed after
successful release testing confirms no issues.
Special case:
Wix5 has removed the property for 'ShowFilesInUse'. Now, whenever a file
is in use during installation, a FilesInUse pop-upwill automatically
appear asking for the next step. To ensure this doesn't interfere with
scenarios that require silent installation (e.g. Winget method), we’ve
handled it using the bafunction approach.
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
- [ ] Closes: #xxx
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx
<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments
<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
---------
Co-authored-by: Jerry Xu <n.xu@outlook.com>
Co-authored-by: Kai Tao <69313318+vanzue@users.noreply.github.com>
Co-authored-by: leileizhang <leilzh@microsoft.com>
Co-authored-by: Kai Tao (from Dev Box) <kaitao@microsoft.com>
Co-authored-by: vanzue <vanzue@outlook.com>
2025-08-25 18:39:11 +08:00
|
|
|
|
|
|
|
|
if (errorCode)
|
|
|
|
|
{
|
|
|
|
|
hr = E_FAIL;
|
|
|
|
|
ExitOnFailure(hr, "Unable to copy Powershell modules file");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LExit:
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
|
{
|
|
|
|
|
er = ERROR_SUCCESS;
|
|
|
|
|
Logger::info(L"DSC module was installed!");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
er = ERROR_INSTALL_FAILURE;
|
|
|
|
|
Logger::error(L"Couldn't install DSC module!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UINT __stdcall UninstallDSCModuleCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
|
|
hr = WcaInitialize(hInstall, "UninstallDSCModuleCA");
|
|
|
|
|
ExitOnFailure(hr, "Failed to initialize");
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
const auto baseModulesPath = GetUserPowerShellModulesPath();
|
|
|
|
|
if (baseModulesPath.empty())
|
|
|
|
|
{
|
|
|
|
|
hr = E_FAIL;
|
|
|
|
|
ExitOnFailure(hr, "Unable to determine Powershell modules path");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const auto powerToysModulePath = baseModulesPath / L"Microsoft.PowerToys.Configure";
|
|
|
|
|
const auto versionedModulePath = powerToysModulePath / (get_product_version(false) + L".0");
|
|
|
|
|
|
|
|
|
|
std::error_code errorCode;
|
|
|
|
|
|
|
|
|
|
for (const auto *filename : {DSC_CONFIGURE_PSD1_NAME, DSC_CONFIGURE_PSM1_NAME})
|
|
|
|
|
{
|
Initial DSC v3 support for PowerToys (#41132)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
Tasks checklist
- [X] Implement DSC infra in PowerToys
- [X] Implement Settings DSC resource
- [X] Implement Get, Set, Test, Export, Schema
- [X] Generate manifest (DSC resource JSON)
- [X] Added Unit Tests
- [x] Add `NJsonSchema` v11.4.0 to the stream
- [x] Package the manifest files so dsc.exe can discover them
- [x] Add `PowerToys.DSC.exe` to the PATH (maybe?)
- [x] Add `InstallLocation` in the registry key so `winget configue
export` can export the PowerToys DSC resources
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
- [X] Closes: #37276
- [X] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [X] **Tests:** Added/updated and all pass
- [X] **Localization:** All end-user-facing strings can be localized
- [x] **Dev docs:** Added/updated
- [x] **New binaries:** Added on the required places
- [x] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [x] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [x] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [x] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [x] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx
<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments
<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
---------
Co-authored-by: vanzue <vanzue@outlook.com>
Co-authored-by: Kai Tao (from Dev Box) <kaitao@microsoft.com>
Co-authored-by: Leilei Zhang <leilzh@microsoft.com>
2025-09-28 00:12:51 -07:00
|
|
|
std::filesystem::remove(versionedModulePath / filename, errorCode);
|
[Installer] Upgrade the installer from WiX3 to WiX5 (#40877)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
Background: The current PowerToys installer is built using Wix3, which
has now been deprecated. To improve security, service quality, and
community support, we’re upgrading the installer to Wix5.
Implementation:
Created Wix5-based projects(PowerToysSetupVext and
PowerToysSetupCustomActionsVNext) within the installer while retaining
the existing Wix3 project. Both versions are built to generate separate
installation packages. The Wix3-related code will be removed after
successful release testing confirms no issues.
Special case:
Wix5 has removed the property for 'ShowFilesInUse'. Now, whenever a file
is in use during installation, a FilesInUse pop-upwill automatically
appear asking for the next step. To ensure this doesn't interfere with
scenarios that require silent installation (e.g. Winget method), we’ve
handled it using the bafunction approach.
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
- [ ] Closes: #xxx
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx
<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments
<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
---------
Co-authored-by: Jerry Xu <n.xu@outlook.com>
Co-authored-by: Kai Tao <69313318+vanzue@users.noreply.github.com>
Co-authored-by: leileizhang <leilzh@microsoft.com>
Co-authored-by: Kai Tao (from Dev Box) <kaitao@microsoft.com>
Co-authored-by: vanzue <vanzue@outlook.com>
2025-08-25 18:39:11 +08:00
|
|
|
|
|
|
|
|
if (errorCode)
|
|
|
|
|
{
|
|
|
|
|
hr = E_FAIL;
|
|
|
|
|
ExitOnFailure(hr, "Unable to delete DSC file");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const auto *modulePath : {&versionedModulePath, &powerToysModulePath})
|
|
|
|
|
{
|
Initial DSC v3 support for PowerToys (#41132)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
Tasks checklist
- [X] Implement DSC infra in PowerToys
- [X] Implement Settings DSC resource
- [X] Implement Get, Set, Test, Export, Schema
- [X] Generate manifest (DSC resource JSON)
- [X] Added Unit Tests
- [x] Add `NJsonSchema` v11.4.0 to the stream
- [x] Package the manifest files so dsc.exe can discover them
- [x] Add `PowerToys.DSC.exe` to the PATH (maybe?)
- [x] Add `InstallLocation` in the registry key so `winget configue
export` can export the PowerToys DSC resources
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
- [X] Closes: #37276
- [X] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [X] **Tests:** Added/updated and all pass
- [X] **Localization:** All end-user-facing strings can be localized
- [x] **Dev docs:** Added/updated
- [x] **New binaries:** Added on the required places
- [x] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [x] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [x] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [x] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [x] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx
<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments
<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
---------
Co-authored-by: vanzue <vanzue@outlook.com>
Co-authored-by: Kai Tao (from Dev Box) <kaitao@microsoft.com>
Co-authored-by: Leilei Zhang <leilzh@microsoft.com>
2025-09-28 00:12:51 -07:00
|
|
|
std::filesystem::remove(*modulePath, errorCode);
|
[Installer] Upgrade the installer from WiX3 to WiX5 (#40877)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
Background: The current PowerToys installer is built using Wix3, which
has now been deprecated. To improve security, service quality, and
community support, we’re upgrading the installer to Wix5.
Implementation:
Created Wix5-based projects(PowerToysSetupVext and
PowerToysSetupCustomActionsVNext) within the installer while retaining
the existing Wix3 project. Both versions are built to generate separate
installation packages. The Wix3-related code will be removed after
successful release testing confirms no issues.
Special case:
Wix5 has removed the property for 'ShowFilesInUse'. Now, whenever a file
is in use during installation, a FilesInUse pop-upwill automatically
appear asking for the next step. To ensure this doesn't interfere with
scenarios that require silent installation (e.g. Winget method), we’ve
handled it using the bafunction approach.
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
- [ ] Closes: #xxx
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx
<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments
<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
---------
Co-authored-by: Jerry Xu <n.xu@outlook.com>
Co-authored-by: Kai Tao <69313318+vanzue@users.noreply.github.com>
Co-authored-by: leileizhang <leilzh@microsoft.com>
Co-authored-by: Kai Tao (from Dev Box) <kaitao@microsoft.com>
Co-authored-by: vanzue <vanzue@outlook.com>
2025-08-25 18:39:11 +08:00
|
|
|
|
|
|
|
|
if (errorCode)
|
|
|
|
|
{
|
|
|
|
|
hr = E_FAIL;
|
|
|
|
|
ExitOnFailure(hr, "Unable to delete DSC folder");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LExit:
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
|
{
|
|
|
|
|
er = ERROR_SUCCESS;
|
|
|
|
|
Logger::info(L"DSC module was uninstalled!");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
er = ERROR_INSTALL_FAILURE;
|
|
|
|
|
Logger::error(L"Couldn't uninstall DSC module!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UINT __stdcall InstallEmbeddedMSIXCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
hr = WcaInitialize(hInstall, "InstallEmbeddedMSIXCA");
|
|
|
|
|
ExitOnFailure(hr, "Failed to initialize");
|
|
|
|
|
|
|
|
|
|
if (auto msix = RcResource::create(IDR_BIN_MSIX_HELLO_PACKAGE, L"BIN", DLL_HANDLE))
|
|
|
|
|
{
|
|
|
|
|
Logger::info(L"Extracted MSIX");
|
|
|
|
|
// TODO: Use to activate embedded MSIX
|
|
|
|
|
const auto msix_path = std::filesystem::temp_directory_path() / "hello_package.msix";
|
|
|
|
|
if (!msix->saveAsFile(msix_path))
|
|
|
|
|
{
|
|
|
|
|
ExitOnFailure(hr, "Failed to save msix");
|
|
|
|
|
}
|
|
|
|
|
Logger::info(L"Saved MSIX");
|
|
|
|
|
using namespace winrt::Windows::Management::Deployment;
|
|
|
|
|
using namespace winrt::Windows::Foundation;
|
|
|
|
|
|
|
|
|
|
Uri msix_uri{msix_path.wstring()};
|
|
|
|
|
PackageManager pm;
|
|
|
|
|
auto result = pm.AddPackageAsync(msix_uri, nullptr, DeploymentOptions::None).get();
|
|
|
|
|
if (!result)
|
|
|
|
|
{
|
|
|
|
|
ExitOnFailure(hr, "Failed to AddPackage");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Logger::info(L"MSIX[s] were installed!");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ExitOnFailure(hr, "Failed to extract msix");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LExit:
|
|
|
|
|
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UINT __stdcall UninstallEmbeddedMSIXCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
using namespace winrt::Windows::Management::Deployment;
|
|
|
|
|
using namespace winrt::Windows::Foundation;
|
|
|
|
|
// TODO: This must be replaced with the actual publisher and package name
|
|
|
|
|
const wchar_t package_name[] = L"46b35c25-b593-48d5-aeb1-d3e9c3b796e9";
|
|
|
|
|
const wchar_t publisher[] = L"CN=yuyoyuppe";
|
|
|
|
|
PackageManager pm;
|
|
|
|
|
|
|
|
|
|
hr = WcaInitialize(hInstall, "UninstallEmbeddedMSIXCA");
|
|
|
|
|
ExitOnFailure(hr, "Failed to initialize");
|
|
|
|
|
|
|
|
|
|
for (const auto &p : pm.FindPackagesForUser({}, package_name, publisher))
|
|
|
|
|
{
|
|
|
|
|
auto result = pm.RemovePackageAsync(p.Id().FullName()).get();
|
|
|
|
|
if (result)
|
|
|
|
|
{
|
|
|
|
|
Logger::info(L"MSIX was uninstalled!");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger::error(L"Couldn't uninstall MSIX!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LExit:
|
|
|
|
|
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
Introduce shared sparse package identity for PowerToys (#42352)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
This pull request adds support for building, installing, and managing a
shared sparse MSIX package to grant package identity to select Win32
components in PowerToys. It introduces a new `PackageIdentity` project,
updates the installer to handle the new MSIX package during
install/uninstall, and provides developer documentation for working with
the sparse package. Additionally, new dependencies and signing rules are
included to support these changes.
**Sparse Package Identity Support**
* Added new `PackageIdentity` project to the solution for building the
sparse MSIX package, and included it in solution/project build
configurations (`PowerToys.sln`).
[[1]](diffhunk://#diff-ca837ce490070b91656ffffe31cbad8865ba9174e0f020231f77baf35ff3f811R29)
[[2]](diffhunk://#diff-ca837ce490070b91656ffffe31cbad8865ba9174e0f020231f77baf35ff3f811R54-R55)
[[3]](diffhunk://#diff-ca837ce490070b91656ffffe31cbad8865ba9174e0f020231f77baf35ff3f811R873-R880)
* Added developer documentation (`sparse-package.md`) and updated
documentation indexes to describe how to build, register, and consume
the sparse MSIX package.
[[1]](diffhunk://#diff-b4e39fb55a49c6de336d5847d75a55dd1d14840578da0ed9130f0130b61b34aaR1-R87)
[[2]](diffhunk://#diff-d0f204e503506a26ef2aa3605a8d64ac353393526fb5dcf48d4287c821f3edbcR31)
[[3]](diffhunk://#diff-430296c8d28f70d8a0164b44d7dfc30ffb1fb32466dad181947f35885b7f28d1R13)
**Installer Enhancements**
* Implemented new custom actions in the installer to install and
uninstall the `PowerToysSparse.msix` package, supporting both per-user
and machine-level scenarios (`CustomAction.cpp`, `CustomAction.def`,
`Product.wxs`).
[[1]](diffhunk://#diff-a7680a20bf0315cff463a95588a100c99d2afc53030f6e947f1f1dcaca5eefd7R597-R806)
[[2]](diffhunk://#diff-79daec0ccfcea63a2f3acb7d811b8b508529921123c754111bbccbea98b2bd74R36-R37)
[[3]](diffhunk://#diff-c12203517db7cde9ad34df9e6611457d1d3c7bc8eb7d58e06739887d3c1034afR115)
[[4]](diffhunk://#diff-c12203517db7cde9ad34df9e6611457d1d3c7bc8eb7d58e06739887d3c1034afR127)
[[5]](diffhunk://#diff-c12203517db7cde9ad34df9e6611457d1d3c7bc8eb7d58e06739887d3c1034afR149)
[[6]](diffhunk://#diff-c12203517db7cde9ad34df9e6611457d1d3c7bc8eb7d58e06739887d3c1034afR205-R210)
**Build and Dependency Updates**
* Added new NuGet package dependencies for Windows App SDK AI and
Runtime to support MSIX and sparse package features
(`Directory.Packages.props`).
* Updated signing pipeline to include the new `PowerToysSparse.msix`
artifact (`.pipelines/ESRPSigning_core.json`).
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
- [ ] Closes: #xxx
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx
<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments
<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
---------
Co-authored-by: Gordon Lam (SH) <yeelam@microsoft.com>
2025-10-20 08:52:49 +08:00
|
|
|
UINT __stdcall InstallPackageIdentityMSIXCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
LPWSTR customActionData = nullptr;
|
|
|
|
|
std::wstring installFolderPath;
|
|
|
|
|
std::wstring installScope;
|
|
|
|
|
std::wstring msixPath;
|
|
|
|
|
std::wstring data;
|
|
|
|
|
size_t delimiterPos;
|
|
|
|
|
bool isMachineLevel = false;
|
|
|
|
|
|
|
|
|
|
hr = WcaInitialize(hInstall, "InstallPackageIdentityMSIXCA");
|
|
|
|
|
ExitOnFailure(hr, "Failed to initialize");
|
|
|
|
|
|
|
|
|
|
hr = WcaGetProperty(L"CustomActionData", &customActionData);
|
|
|
|
|
ExitOnFailure(hr, "Failed to get CustomActionData property");
|
|
|
|
|
|
|
|
|
|
// Parse CustomActionData: "[INSTALLFOLDER];[InstallScope]"
|
|
|
|
|
data = customActionData;
|
|
|
|
|
delimiterPos = data.find(L';');
|
|
|
|
|
installFolderPath = data.substr(0, delimiterPos);
|
|
|
|
|
installScope = data.substr(delimiterPos + 1);
|
|
|
|
|
|
|
|
|
|
// Check if this is a machine-level installation
|
|
|
|
|
if (installScope == L"perMachine")
|
|
|
|
|
{
|
|
|
|
|
isMachineLevel = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Logger::info(L"Installing PackageIdentity MSIX - perUser: {}", !isMachineLevel);
|
|
|
|
|
|
|
|
|
|
// Construct path to PackageIdentity MSIX
|
|
|
|
|
msixPath = installFolderPath;
|
|
|
|
|
msixPath += L"PowerToysSparse.msix";
|
|
|
|
|
|
|
|
|
|
if (std::filesystem::exists(msixPath))
|
|
|
|
|
{
|
|
|
|
|
using namespace winrt::Windows::Management::Deployment;
|
|
|
|
|
using namespace winrt::Windows::Foundation;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
Fix MSIX sparse package DACL contamination breaking File Explorer preview handlers (#47177)
## Summary
Moves the MSIX sparse package's `ExternalLocation` from the PowerToys
root install folder to the `WinUI3Apps\` subfolder, isolating DACL
contamination from preview handler DLLs.
## Problem
On Windows 23H2/24H2/25H2, MSIX sparse package registration adds
AppContainer SIDs (`S-1-15-2-*` / `S-1-15-3-*`) to the DACL of the
`ExternalLocation` folder. Since `ExternalLocation` pointed to the
PowerToys root install folder, this broke File Explorer preview handlers
— `prevhost.exe` (running at LOW integrity) could no longer load preview
handler DLLs (`.txt`, `.md`, `.pdf`, `.svg`, etc.).
## Fix
- **`CustomAction.cpp`**: Changed `ExternalLocation` from
`installFolderPath` → `installFolderPath + L"WinUI3Apps\\"`
- **`AppxManifest.xml`**: Removed unused PowerOCR `<Application>` entry;
stripped `WinUI3Apps\` prefix from `Executable` paths (now relative to
new ExternalLocation)
- **`CmdPal.Ext.PowerToys.csproj`**: Moved `OutputPath` to `WinUI3Apps\`
so the AOT-compiled extension EXE resolves correctly under the new
ExternalLocation
- **WiX installer files**: Updated source/install paths for KBM assets,
CmdPal satellite assemblies, and `CommandPalette.Extensions.winmd` that
moved with the CmdPal output
- **ESRP signing**: Updated CmdPal dll/exe paths to include
`WinUI3Apps\` prefix
## Validation
| Test | 25H2 | 23H2 |
|------|------|------|
| DACL isolation (no S-1-15-* on root) | ✅ | ✅ |
| Preview handlers (.txt, .md, .pdf, .svg) | ✅ | ✅ |
| Peek | ✅ | ✅ |
| Context menus (PowerRename, FileLocksmith, ImageResizer, New+) | ✅ | ✅
|
| Upgrade path (old → new) | ✅ | ✅ |
## Files changed (12)
- `installer/PowerToysSetupCustomActionsVNext/CustomAction.cpp` — core
fix
- `src/PackageIdentity/AppxManifest.xml` — manifest cleanup
-
`src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Microsoft.CmdPal.Ext.PowerToys.csproj`
— output path
-
`src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Helpers/PowerToysResourcesHelper.cs`
— icon path
- `installer/PowerToysSetupVNext/BaseApplications.wxs` — winmd source
path
- `installer/PowerToysSetupVNext/KeyboardManager.wxs` — KBM assets path
- `installer/PowerToysSetupVNext/Resources.wxs` — CmdPal satellite paths
- `installer/PowerToysSetupVNext/generateAllFileComponents.ps1` — scan
path
- `.pipelines/ESRPSigning_core.json` — signing paths
- `src/PackageIdentity/BuildSparsePackage.ps1` — dev script hint
- `src/PackageIdentity/readme.md` — docs
- `doc/devdocs/modules/cmdpal/powertoys-extension-local-development.md`
— docs
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-24 22:37:59 +08:00
|
|
|
std::wstring externalLocation = installFolderPath + L"WinUI3Apps\\"; // External content location (WinUI3Apps subfolder to isolate DACL changes from preview handler DLLs)
|
Introduce shared sparse package identity for PowerToys (#42352)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
This pull request adds support for building, installing, and managing a
shared sparse MSIX package to grant package identity to select Win32
components in PowerToys. It introduces a new `PackageIdentity` project,
updates the installer to handle the new MSIX package during
install/uninstall, and provides developer documentation for working with
the sparse package. Additionally, new dependencies and signing rules are
included to support these changes.
**Sparse Package Identity Support**
* Added new `PackageIdentity` project to the solution for building the
sparse MSIX package, and included it in solution/project build
configurations (`PowerToys.sln`).
[[1]](diffhunk://#diff-ca837ce490070b91656ffffe31cbad8865ba9174e0f020231f77baf35ff3f811R29)
[[2]](diffhunk://#diff-ca837ce490070b91656ffffe31cbad8865ba9174e0f020231f77baf35ff3f811R54-R55)
[[3]](diffhunk://#diff-ca837ce490070b91656ffffe31cbad8865ba9174e0f020231f77baf35ff3f811R873-R880)
* Added developer documentation (`sparse-package.md`) and updated
documentation indexes to describe how to build, register, and consume
the sparse MSIX package.
[[1]](diffhunk://#diff-b4e39fb55a49c6de336d5847d75a55dd1d14840578da0ed9130f0130b61b34aaR1-R87)
[[2]](diffhunk://#diff-d0f204e503506a26ef2aa3605a8d64ac353393526fb5dcf48d4287c821f3edbcR31)
[[3]](diffhunk://#diff-430296c8d28f70d8a0164b44d7dfc30ffb1fb32466dad181947f35885b7f28d1R13)
**Installer Enhancements**
* Implemented new custom actions in the installer to install and
uninstall the `PowerToysSparse.msix` package, supporting both per-user
and machine-level scenarios (`CustomAction.cpp`, `CustomAction.def`,
`Product.wxs`).
[[1]](diffhunk://#diff-a7680a20bf0315cff463a95588a100c99d2afc53030f6e947f1f1dcaca5eefd7R597-R806)
[[2]](diffhunk://#diff-79daec0ccfcea63a2f3acb7d811b8b508529921123c754111bbccbea98b2bd74R36-R37)
[[3]](diffhunk://#diff-c12203517db7cde9ad34df9e6611457d1d3c7bc8eb7d58e06739887d3c1034afR115)
[[4]](diffhunk://#diff-c12203517db7cde9ad34df9e6611457d1d3c7bc8eb7d58e06739887d3c1034afR127)
[[5]](diffhunk://#diff-c12203517db7cde9ad34df9e6611457d1d3c7bc8eb7d58e06739887d3c1034afR149)
[[6]](diffhunk://#diff-c12203517db7cde9ad34df9e6611457d1d3c7bc8eb7d58e06739887d3c1034afR205-R210)
**Build and Dependency Updates**
* Added new NuGet package dependencies for Windows App SDK AI and
Runtime to support MSIX and sparse package features
(`Directory.Packages.props`).
* Updated signing pipeline to include the new `PowerToysSparse.msix`
artifact (`.pipelines/ESRPSigning_core.json`).
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
- [ ] Closes: #xxx
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx
<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments
<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
---------
Co-authored-by: Gordon Lam (SH) <yeelam@microsoft.com>
2025-10-20 08:52:49 +08:00
|
|
|
Uri externalUri{ externalLocation }; // External location URI for sparse package content
|
|
|
|
|
Uri packageUri{ msixPath }; // The MSIX file URI
|
|
|
|
|
|
|
|
|
|
PackageManager packageManager;
|
|
|
|
|
|
|
|
|
|
if (isMachineLevel)
|
|
|
|
|
{
|
|
|
|
|
// Machine-level installation
|
|
|
|
|
|
|
|
|
|
StagePackageOptions stageOptions;
|
|
|
|
|
stageOptions.ExternalLocationUri(externalUri);
|
|
|
|
|
|
|
|
|
|
auto stageResult = packageManager.StagePackageByUriAsync(packageUri, stageOptions).get();
|
|
|
|
|
|
|
|
|
|
uint32_t stageErrorCode = static_cast<uint32_t>(stageResult.ExtendedErrorCode());
|
|
|
|
|
if (stageErrorCode == 0)
|
|
|
|
|
{
|
|
|
|
|
std::wstring packageFamilyName = L"Microsoft.PowerToys.SparseApp_8wekyb3d8bbwe";
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
auto provisionResult = packageManager.ProvisionPackageForAllUsersAsync(packageFamilyName).get();
|
|
|
|
|
uint32_t provisionErrorCode = static_cast<uint32_t>(provisionResult.ExtendedErrorCode());
|
|
|
|
|
|
|
|
|
|
if (provisionErrorCode != 0)
|
|
|
|
|
{
|
|
|
|
|
Logger::error(L"Machine-level provisioning failed: 0x{:08X}", provisionErrorCode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (const winrt::hresult_error& ex)
|
|
|
|
|
{
|
|
|
|
|
Logger::error(L"Provisioning exception: HRESULT 0x{:08X}", static_cast<uint32_t>(ex.code()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger::error(L"Package staging failed: 0x{:08X}", stageErrorCode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
AddPackageOptions addOptions;
|
|
|
|
|
addOptions.ExternalLocationUri(externalUri);
|
|
|
|
|
|
|
|
|
|
auto addResult = packageManager.AddPackageByUriAsync(packageUri, addOptions).get();
|
|
|
|
|
|
|
|
|
|
if (!addResult.IsRegistered())
|
|
|
|
|
{
|
|
|
|
|
uint32_t errorCode = static_cast<uint32_t>(addResult.ExtendedErrorCode());
|
|
|
|
|
Logger::error(L"Per-user installation failed: 0x{:08X}", errorCode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (const std::exception& ex)
|
|
|
|
|
{
|
|
|
|
|
Logger::error(L"PackageIdentity MSIX installation failed - Exception: {}",
|
|
|
|
|
winrt::to_hstring(ex.what()).c_str());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger::error(L"PackageIdentity MSIX not found: " + msixPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LExit:
|
|
|
|
|
ReleaseStr(customActionData);
|
|
|
|
|
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UINT __stdcall UninstallPackageIdentityMSIXCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
using namespace winrt::Windows::Management::Deployment;
|
|
|
|
|
using namespace winrt::Windows::Foundation;
|
|
|
|
|
|
|
|
|
|
LPWSTR installScope = nullptr;
|
|
|
|
|
bool isMachineLevel = false;
|
|
|
|
|
|
|
|
|
|
PackageManager pm;
|
|
|
|
|
|
|
|
|
|
hr = WcaInitialize(hInstall, "UninstallPackageIdentityMSIXCA");
|
|
|
|
|
ExitOnFailure(hr, "Failed to initialize");
|
|
|
|
|
|
|
|
|
|
// Check if this was a machine-level installation
|
|
|
|
|
hr = WcaGetProperty(L"InstallScope", &installScope);
|
|
|
|
|
if (SUCCEEDED(hr) && installScope && wcscmp(installScope, L"perMachine") == 0)
|
|
|
|
|
{
|
|
|
|
|
isMachineLevel = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Logger::info(L"Uninstalling PackageIdentity MSIX - perUser: {}", !isMachineLevel);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
std::wstring packageFamilyName = L"Microsoft.PowerToys.SparseApp_8wekyb3d8bbwe";
|
|
|
|
|
|
|
|
|
|
if (isMachineLevel)
|
|
|
|
|
{
|
|
|
|
|
// Machine-level uninstallation: deprovision + remove for all users
|
|
|
|
|
|
|
|
|
|
// First deprovision the package
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
auto deprovisionResult = pm.DeprovisionPackageForAllUsersAsync(packageFamilyName).get();
|
|
|
|
|
if (deprovisionResult.IsRegistered())
|
|
|
|
|
{
|
|
|
|
|
Logger::warn(L"Machine-level deprovisioning completed with warnings");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (const winrt::hresult_error& ex)
|
|
|
|
|
{
|
|
|
|
|
Logger::warn(L"Machine-level deprovisioning failed: HRESULT 0x{:08X}", static_cast<uint32_t>(ex.code()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Then remove packages for all users
|
|
|
|
|
auto packages = pm.FindPackagesForUserWithPackageTypes({}, packageFamilyName, PackageTypes::Main);
|
|
|
|
|
for (const auto& package : packages)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
auto machineResult = pm.RemovePackageAsync(package.Id().FullName(), RemovalOptions::RemoveForAllUsers).get();
|
|
|
|
|
if (machineResult.IsRegistered())
|
|
|
|
|
{
|
|
|
|
|
uint32_t errorCode = static_cast<uint32_t>(machineResult.ExtendedErrorCode());
|
|
|
|
|
Logger::error(L"Machine-level removal failed: 0x{:08X} - {}", errorCode, machineResult.ErrorText());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (const winrt::hresult_error& ex)
|
|
|
|
|
{
|
|
|
|
|
Logger::error(L"Machine-level removal exception: HRESULT 0x{:08X}", static_cast<uint32_t>(ex.code()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Per-user uninstallation: standard removal
|
|
|
|
|
|
|
|
|
|
auto packages = pm.FindPackagesForUserWithPackageTypes({}, packageFamilyName, PackageTypes::Main);
|
|
|
|
|
for (const auto& package : packages)
|
|
|
|
|
{
|
|
|
|
|
auto userResult = pm.RemovePackageAsync(package.Id().FullName()).get();
|
|
|
|
|
if (userResult.IsRegistered())
|
|
|
|
|
{
|
|
|
|
|
uint32_t errorCode = static_cast<uint32_t>(userResult.ExtendedErrorCode());
|
|
|
|
|
Logger::error(L"Per-user removal failed: 0x{:08X} - {}", errorCode, userResult.ErrorText());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (const std::exception& ex)
|
|
|
|
|
{
|
|
|
|
|
std::string errorMsg = "Failed to uninstall PackageIdentity MSIX: " + std::string(ex.what());
|
|
|
|
|
Logger::error(errorMsg);
|
|
|
|
|
// Don't fail the entire uninstallation if PackageIdentity fails
|
|
|
|
|
Logger::warn(L"Continuing uninstallation despite PackageIdentity MSIX error");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LExit:
|
|
|
|
|
ReleaseStr(installScope);
|
|
|
|
|
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
[Installer] Upgrade the installer from WiX3 to WiX5 (#40877)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
Background: The current PowerToys installer is built using Wix3, which
has now been deprecated. To improve security, service quality, and
community support, we’re upgrading the installer to Wix5.
Implementation:
Created Wix5-based projects(PowerToysSetupVext and
PowerToysSetupCustomActionsVNext) within the installer while retaining
the existing Wix3 project. Both versions are built to generate separate
installation packages. The Wix3-related code will be removed after
successful release testing confirms no issues.
Special case:
Wix5 has removed the property for 'ShowFilesInUse'. Now, whenever a file
is in use during installation, a FilesInUse pop-upwill automatically
appear asking for the next step. To ensure this doesn't interfere with
scenarios that require silent installation (e.g. Winget method), we’ve
handled it using the bafunction approach.
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
- [ ] Closes: #xxx
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx
<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments
<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
---------
Co-authored-by: Jerry Xu <n.xu@outlook.com>
Co-authored-by: Kai Tao <69313318+vanzue@users.noreply.github.com>
Co-authored-by: leileizhang <leilzh@microsoft.com>
Co-authored-by: Kai Tao (from Dev Box) <kaitao@microsoft.com>
Co-authored-by: vanzue <vanzue@outlook.com>
2025-08-25 18:39:11 +08:00
|
|
|
UINT __stdcall RemoveWindowsServiceByName(std::wstring serviceName)
|
|
|
|
|
{
|
|
|
|
|
SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
|
|
|
|
|
|
|
|
|
|
if (!hSCManager)
|
|
|
|
|
{
|
|
|
|
|
return ERROR_INSTALL_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SC_HANDLE hService = OpenService(hSCManager, serviceName.c_str(), SERVICE_STOP | DELETE);
|
|
|
|
|
if (!hService)
|
|
|
|
|
{
|
|
|
|
|
CloseServiceHandle(hSCManager);
|
|
|
|
|
return ERROR_INSTALL_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SERVICE_STATUS ss;
|
|
|
|
|
if (ControlService(hService, SERVICE_CONTROL_STOP, &ss))
|
|
|
|
|
{
|
|
|
|
|
Sleep(1000);
|
|
|
|
|
while (QueryServiceStatus(hService, &ss))
|
|
|
|
|
{
|
|
|
|
|
if (ss.dwCurrentState == SERVICE_STOP_PENDING)
|
|
|
|
|
{
|
|
|
|
|
Sleep(1000);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOL deleteResult = DeleteService(hService);
|
|
|
|
|
CloseServiceHandle(hService);
|
|
|
|
|
CloseServiceHandle(hSCManager);
|
|
|
|
|
|
|
|
|
|
if (!deleteResult)
|
|
|
|
|
{
|
|
|
|
|
return ERROR_INSTALL_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UINT __stdcall UnsetAdvancedPasteAPIKeyCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
hr = WcaInitialize(hInstall, "UnsetAdvancedPasteAPIKey");
|
|
|
|
|
ExitOnFailure(hr, "Failed to initialize");
|
|
|
|
|
|
2025-11-14 16:15:15 +08:00
|
|
|
winrt::Windows::Security::Credentials::PasswordVault vault;
|
|
|
|
|
|
|
|
|
|
auto hasPrefix = [](std::wstring_view value, wchar_t const* prefix) {
|
|
|
|
|
std::wstring_view prefixView{ prefix };
|
|
|
|
|
return value.compare(0, prefixView.size(), prefixView) == 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const wchar_t* resourcePrefixes[] = {
|
|
|
|
|
L"https://platform.openai.com/api-keys",
|
|
|
|
|
L"https://azure.microsoft.com/products/ai-services/openai-service",
|
|
|
|
|
L"https://azure.microsoft.com/products/ai-services/ai-inference",
|
|
|
|
|
L"https://console.mistral.ai/account/api-keys",
|
|
|
|
|
L"https://ai.google.dev/",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const wchar_t* usernamePrefixes[] = {
|
|
|
|
|
L"PowerToys_AdvancedPaste_",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto credentials = vault.RetrieveAll();
|
|
|
|
|
for (auto const& credential : credentials)
|
|
|
|
|
{
|
|
|
|
|
bool shouldRemove = false;
|
|
|
|
|
|
|
|
|
|
std::wstring resource{ credential.Resource() };
|
|
|
|
|
for (auto const prefix : resourcePrefixes)
|
|
|
|
|
{
|
|
|
|
|
if (hasPrefix(resource, prefix))
|
|
|
|
|
{
|
|
|
|
|
shouldRemove = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!shouldRemove)
|
|
|
|
|
{
|
|
|
|
|
std::wstring username{ credential.UserName() };
|
|
|
|
|
for (auto const prefix : usernamePrefixes)
|
|
|
|
|
{
|
|
|
|
|
if (hasPrefix(username, prefix))
|
|
|
|
|
{
|
|
|
|
|
shouldRemove = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!shouldRemove)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
vault.Remove(credential);
|
|
|
|
|
}
|
|
|
|
|
catch (...)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
[Installer] Upgrade the installer from WiX3 to WiX5 (#40877)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
Background: The current PowerToys installer is built using Wix3, which
has now been deprecated. To improve security, service quality, and
community support, we’re upgrading the installer to Wix5.
Implementation:
Created Wix5-based projects(PowerToysSetupVext and
PowerToysSetupCustomActionsVNext) within the installer while retaining
the existing Wix3 project. Both versions are built to generate separate
installation packages. The Wix3-related code will be removed after
successful release testing confirms no issues.
Special case:
Wix5 has removed the property for 'ShowFilesInUse'. Now, whenever a file
is in use during installation, a FilesInUse pop-upwill automatically
appear asking for the next step. To ensure this doesn't interfere with
scenarios that require silent installation (e.g. Winget method), we’ve
handled it using the bafunction approach.
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
- [ ] Closes: #xxx
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx
<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments
<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
---------
Co-authored-by: Jerry Xu <n.xu@outlook.com>
Co-authored-by: Kai Tao <69313318+vanzue@users.noreply.github.com>
Co-authored-by: leileizhang <leilzh@microsoft.com>
Co-authored-by: Kai Tao (from Dev Box) <kaitao@microsoft.com>
Co-authored-by: vanzue <vanzue@outlook.com>
2025-08-25 18:39:11 +08:00
|
|
|
}
|
|
|
|
|
catch (...)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LExit:
|
|
|
|
|
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UINT __stdcall UninstallCommandNotFoundModuleCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
std::wstring installationFolder;
|
|
|
|
|
std::string command;
|
|
|
|
|
|
|
|
|
|
hr = WcaInitialize(hInstall, "UninstallCommandNotFoundModule");
|
|
|
|
|
ExitOnFailure(hr, "Failed to initialize");
|
|
|
|
|
|
|
|
|
|
hr = getInstallFolder(hInstall, installationFolder);
|
|
|
|
|
ExitOnFailure(hr, "Failed to get installFolder.");
|
|
|
|
|
|
|
|
|
|
#ifdef _M_ARM64
|
|
|
|
|
command = "powershell.exe";
|
|
|
|
|
command += " ";
|
|
|
|
|
command += "-NoProfile -NonInteractive -NoLogo -WindowStyle Hidden -ExecutionPolicy Unrestricted";
|
|
|
|
|
command += " -Command ";
|
|
|
|
|
command += "\"[Environment]::SetEnvironmentVariable('PATH', [Environment]::GetEnvironmentVariable('PATH', 'Machine') + ';' + [Environment]::GetEnvironmentVariable('PATH', 'User'), 'Process');";
|
|
|
|
|
command += "pwsh.exe -NoProfile -NonInteractive -NoLogo -WindowStyle Hidden -ExecutionPolicy Unrestricted -File '" + winrt::to_string(installationFolder) + "\\WinUI3Apps\\Assets\\Settings\\Scripts\\DisableModule.ps1" + "'\"";
|
|
|
|
|
#else
|
|
|
|
|
command = "pwsh.exe";
|
|
|
|
|
command += " ";
|
|
|
|
|
command += "-NoProfile -NonInteractive -NoLogo -WindowStyle Hidden -ExecutionPolicy Unrestricted -File \"" + winrt::to_string(installationFolder) + "\\WinUI3Apps\\Assets\\Settings\\Scripts\\DisableModule.ps1" + "\"";
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
system(command.c_str());
|
|
|
|
|
|
|
|
|
|
LExit:
|
|
|
|
|
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UINT __stdcall UpgradeCommandNotFoundModuleCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
std::wstring installationFolder;
|
|
|
|
|
std::string command;
|
|
|
|
|
|
|
|
|
|
hr = WcaInitialize(hInstall, "UpgradeCommandNotFoundModule");
|
|
|
|
|
ExitOnFailure(hr, "Failed to initialize");
|
|
|
|
|
|
|
|
|
|
hr = getInstallFolder(hInstall, installationFolder);
|
|
|
|
|
ExitOnFailure(hr, "Failed to get installFolder.");
|
|
|
|
|
|
|
|
|
|
command = "pwsh.exe";
|
|
|
|
|
command += " ";
|
|
|
|
|
command += "-NoProfile -NonInteractive -NoLogo -WindowStyle Hidden -ExecutionPolicy Unrestricted -File \"" + winrt::to_string(installationFolder) + "\\WinUI3Apps\\Assets\\Settings\\Scripts\\UpgradeModule.ps1" + "\"";
|
|
|
|
|
|
|
|
|
|
system(command.c_str());
|
|
|
|
|
|
|
|
|
|
LExit:
|
|
|
|
|
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UINT __stdcall UninstallServicesCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
hr = WcaInitialize(hInstall, "UninstallServicesCA");
|
|
|
|
|
|
|
|
|
|
ExitOnFailure(hr, "Failed to initialize");
|
|
|
|
|
|
|
|
|
|
hr = RemoveWindowsServiceByName(L"PowerToys.MWB.Service");
|
|
|
|
|
|
|
|
|
|
LExit:
|
|
|
|
|
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Removes all Scheduled Tasks in the PowerToys folder and deletes the folder afterwards.
|
|
|
|
|
// Based on the Task Scheduler Displaying Task Names and State example:
|
|
|
|
|
// https://learn.microsoft.com/windows/desktop/TaskSchd/displaying-task-names-and-state--c---/
|
|
|
|
|
UINT __stdcall RemoveScheduledTasksCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
|
|
ITaskService *pService = nullptr;
|
|
|
|
|
ITaskFolder *pTaskFolder = nullptr;
|
|
|
|
|
IRegisteredTaskCollection *pTaskCollection = nullptr;
|
|
|
|
|
ITaskFolder *pRootFolder = nullptr;
|
|
|
|
|
LONG numTasks = 0;
|
|
|
|
|
|
|
|
|
|
hr = WcaInitialize(hInstall, "RemoveScheduledTasksCA");
|
|
|
|
|
ExitOnFailure(hr, "Failed to initialize");
|
|
|
|
|
|
|
|
|
|
Logger::info(L"RemoveScheduledTasksCA Initialized.");
|
|
|
|
|
|
|
|
|
|
// COM and Security Initialization is expected to have been done by the MSI.
|
|
|
|
|
// It couldn't be done in the DLL, anyway.
|
|
|
|
|
// ------------------------------------------------------
|
|
|
|
|
// Create an instance of the Task Service.
|
|
|
|
|
hr = CoCreateInstance(CLSID_TaskScheduler,
|
|
|
|
|
nullptr,
|
|
|
|
|
CLSCTX_INPROC_SERVER,
|
|
|
|
|
IID_ITaskService,
|
|
|
|
|
reinterpret_cast<void **>(&pService));
|
|
|
|
|
ExitOnFailure(hr, "Failed to create an instance of ITaskService: %x", hr);
|
|
|
|
|
|
|
|
|
|
// Connect to the task service.
|
|
|
|
|
hr = pService->Connect(_variant_t(), _variant_t(), _variant_t(), _variant_t());
|
|
|
|
|
ExitOnFailure(hr, "ITaskService::Connect failed: %x", hr);
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------
|
|
|
|
|
// Get the PowerToys task folder.
|
|
|
|
|
hr = pService->GetFolder(_bstr_t(L"\\PowerToys"), &pTaskFolder);
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
|
{
|
|
|
|
|
// Folder doesn't exist. No need to delete anything.
|
|
|
|
|
Logger::info(L"The PowerToys scheduled task folder wasn't found. Nothing to delete.");
|
|
|
|
|
hr = S_OK;
|
|
|
|
|
ExitFunction();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------
|
|
|
|
|
// Get the registered tasks in the folder.
|
|
|
|
|
hr = pTaskFolder->GetTasks(TASK_ENUM_HIDDEN, &pTaskCollection);
|
|
|
|
|
ExitOnFailure(hr, "Cannot get the registered tasks: %x", hr);
|
|
|
|
|
|
|
|
|
|
hr = pTaskCollection->get_Count(&numTasks);
|
|
|
|
|
for (LONG i = 0; i < numTasks; i++)
|
|
|
|
|
{
|
|
|
|
|
// Delete all the tasks found.
|
|
|
|
|
// If some tasks can't be deleted, the folder won't be deleted later and the user will still be notified.
|
|
|
|
|
IRegisteredTask *pRegisteredTask = nullptr;
|
|
|
|
|
hr = pTaskCollection->get_Item(_variant_t(i + 1), &pRegisteredTask);
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
|
{
|
|
|
|
|
BSTR taskName = nullptr;
|
|
|
|
|
hr = pRegisteredTask->get_Name(&taskName);
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
|
{
|
|
|
|
|
hr = pTaskFolder->DeleteTask(taskName, 0);
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
|
{
|
|
|
|
|
Logger::error(L"Cannot delete the {} task: {}", taskName, hr);
|
|
|
|
|
}
|
|
|
|
|
SysFreeString(taskName);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger::error(L"Cannot get the registered task name: {}", hr);
|
|
|
|
|
}
|
|
|
|
|
pRegisteredTask->Release();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger::error(L"Cannot get the registered task item at index={}: {}", i + 1, hr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------
|
|
|
|
|
// Get the pointer to the root task folder and delete the PowerToys subfolder.
|
|
|
|
|
hr = pService->GetFolder(_bstr_t(L"\\"), &pRootFolder);
|
|
|
|
|
ExitOnFailure(hr, "Cannot get Root Folder pointer: %x", hr);
|
|
|
|
|
hr = pRootFolder->DeleteFolder(_bstr_t(L"PowerToys"), 0);
|
|
|
|
|
pRootFolder->Release();
|
|
|
|
|
ExitOnFailure(hr, "Cannot delete the PowerToys folder: %x", hr);
|
|
|
|
|
|
|
|
|
|
Logger::info(L"Deleted the PowerToys Task Scheduler folder.");
|
|
|
|
|
|
|
|
|
|
LExit:
|
|
|
|
|
if (pService)
|
|
|
|
|
{
|
|
|
|
|
pService->Release();
|
|
|
|
|
}
|
|
|
|
|
if (pTaskFolder)
|
|
|
|
|
{
|
|
|
|
|
pTaskFolder->Release();
|
|
|
|
|
}
|
|
|
|
|
if (pTaskCollection)
|
|
|
|
|
{
|
|
|
|
|
pTaskCollection->Release();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!SUCCEEDED(hr))
|
|
|
|
|
{
|
|
|
|
|
PMSIHANDLE hRecord = MsiCreateRecord(0);
|
|
|
|
|
MsiRecordSetString(hRecord, 0, TEXT("Failed to remove the PowerToys folder from the scheduled task. These can be removed manually later."));
|
|
|
|
|
MsiProcessMessage(hInstall, static_cast<INSTALLMESSAGE>(INSTALLMESSAGE_WARNING + MB_OK), hRecord);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
[New+] Hide existing new - remake (#44979)
## Summary of the Pull Request
- Add the ability for users and admins (GPO) to control whether to
display built in New on the context menu.
- Changes to the setting are immediately reflected in the experience.
- Built-in New is restored on uninstall.
## PR Checklist
Note: Supersedes https://github.com/microsoft/PowerToys/pull/39843
- [x] **Closes**: [New+] Replace default New entry #37545 and Replace
"New" with New+ option #37946
- [x] **Communication:** Discussed with @niels9001 - 1/22/2025
- [x] **Tests:** Completed manual test pass see highlight below
- [x] **Localization:** All end-user-facing strings can be localized
- [x] **Dev docs:** Updated "doc\devdocs\modules\newplus.md"
- [n/a] **New binaries:** Added on the required places
- [n/a] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [x] [WXS for installer] Updated installer (uninstall custom action)
- [n/a] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [n/a] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [No] **Documentation updated:** Pending, coming soon. (original PR
https://github.com/MicrosoftDocs/windows-dev-docs/pull/5473)
## Detailed Description of the Pull Request / Additional comments
Added the ability for users' admins' to display Windows built-in New or
not
I'm NOT aware of an official supported way to do this, so I'm achieving
this by adding an invalid context menu handler in place of New in the
Computer\HKEY_CURRENT_USER\Software\Classes\Directory\background\ShellEx\ContextMenuHandlers\New
Changes are immediate, after applying the change, built-in New is
shown/hidden accordingly
Updates to New+ Settings UI
New setting introduced to track user' preference (saved to
newplus/settings.json)
GPO setting introduced for control New visibility via GPO (GPO wins over
user preference)
Updates to New+ power_module.cpp
When runner is running new plus will also apply built-in New admin GPO
and user preference (GPO wins over user preference) to ensure correct
behavior on setting restore and GPO application.
Updates to installer
Uninstall always reenable built-in "New" context menu
Updated DevDoc
Added a note on how to manually restore built-in New
## Validation Steps Performed
Windows 11 x64
Settings UI
New+ enabled
New+ disabled
GPO setting enabled
GPO settings disabled
Manually updating newplus/settings.json
Windows 11 ARM64
I tested the reg hack manually, but didn't go through a full pass.
Windows 10 x64
NOT tested.
Windows 11, Settings, New+ Disabled and no GPO
<img width="1040" height="1002" alt="image"
src="https://github.com/user-attachments/assets/1b827b10-f009-4b0b-954f-d9311d40d201"
/>
Windows 11, Settings, New+ Enabled and no GPO
<img width="1015" height="781" alt="image"
src="https://github.com/user-attachments/assets/a5fa09d3-7fd3-4830-99a4-5f2ac9ce1a38"
/>
Hide built-in New: Off (the default)
<img width="321" height="417" alt="image"
src="https://github.com/user-attachments/assets/355fea60-bbb8-4f11-b648-291aaf0c4a6d"
/>
Hide built-in New: On
<img width="1015" height="87" alt="image"
src="https://github.com/user-attachments/assets/e83e45c4-6b67-443b-b045-26e7dda2cf46"
/>
Modern
<img width="308" height="360" alt="image"
src="https://github.com/user-attachments/assets/b164b240-6e67-410c-8481-7db3ee3225b7"
/>
Classic
<img width="308" height="289" alt="image"
src="https://github.com/user-attachments/assets/e2b6c262-a311-454c-9c76-40cb11ff2970"
/>
Disabling New+ also unhide New
<img width="1031" height="569" alt="image"
src="https://github.com/user-attachments/assets/29b8dae7-8190-4e64-b106-c6861e472a3d"
/>
<img width="308" height="353" alt="image"
src="https://github.com/user-attachments/assets/e1977d6b-dc85-4db4-b9ab-c7bb2b27dde2"
/>
Windows 11, Settings, New+ Enabled and with GPO
Hide built-in New: GPO enabled
<img width="1020" height="691" alt="image"
src="https://github.com/user-attachments/assets/75053ab8-92c6-4d38-b1b8-9b0d8293c207"
/>
Hide built-in New: GPO disabled
<img width="1050" height="161" alt="image"
src="https://github.com/user-attachments/assets/1a50b841-ff01-4662-a923-aee63717c834"
/>
2026-03-01 03:32:38 -08:00
|
|
|
UINT __stdcall RestoreBuiltInNewContextMenuCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
hr = WcaInitialize(hInstall, "RestoreBuiltInNewContextMenuCA");
|
|
|
|
|
|
|
|
|
|
constexpr wchar_t built_in_new_registry_path[] = LR"(Software\Classes\Directory\Background\ShellEx\ContextMenuHandlers\New)";
|
|
|
|
|
|
|
|
|
|
HKEY key{};
|
|
|
|
|
|
|
|
|
|
if (RegOpenKeyExW(HKEY_CURRENT_USER,
|
|
|
|
|
built_in_new_registry_path,
|
|
|
|
|
0,
|
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
|
&key) != ERROR_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
return WcaFinalize(ERROR_SUCCESS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (RegDeleteValueW(key, nullptr) != ERROR_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
RegCloseKey(key);
|
|
|
|
|
return WcaFinalize(ERROR_SUCCESS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RegCloseKey(key);
|
|
|
|
|
|
|
|
|
|
return WcaFinalize(ERROR_SUCCESS);
|
|
|
|
|
}
|
|
|
|
|
|
[Installer] Upgrade the installer from WiX3 to WiX5 (#40877)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
Background: The current PowerToys installer is built using Wix3, which
has now been deprecated. To improve security, service quality, and
community support, we’re upgrading the installer to Wix5.
Implementation:
Created Wix5-based projects(PowerToysSetupVext and
PowerToysSetupCustomActionsVNext) within the installer while retaining
the existing Wix3 project. Both versions are built to generate separate
installation packages. The Wix3-related code will be removed after
successful release testing confirms no issues.
Special case:
Wix5 has removed the property for 'ShowFilesInUse'. Now, whenever a file
is in use during installation, a FilesInUse pop-upwill automatically
appear asking for the next step. To ensure this doesn't interfere with
scenarios that require silent installation (e.g. Winget method), we’ve
handled it using the bafunction approach.
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
- [ ] Closes: #xxx
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx
<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments
<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
---------
Co-authored-by: Jerry Xu <n.xu@outlook.com>
Co-authored-by: Kai Tao <69313318+vanzue@users.noreply.github.com>
Co-authored-by: leileizhang <leilzh@microsoft.com>
Co-authored-by: Kai Tao (from Dev Box) <kaitao@microsoft.com>
Co-authored-by: vanzue <vanzue@outlook.com>
2025-08-25 18:39:11 +08:00
|
|
|
UINT __stdcall TelemetryLogInstallSuccessCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
|
|
hr = WcaInitialize(hInstall, "TelemetryLogInstallSuccessCA");
|
|
|
|
|
ExitOnFailure(hr, "Failed to initialize");
|
|
|
|
|
|
|
|
|
|
TraceLoggingWriteWrapper(
|
|
|
|
|
g_hProvider,
|
|
|
|
|
"Install_Success",
|
|
|
|
|
TraceLoggingWideString(get_product_version().c_str(), "Version"),
|
|
|
|
|
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
|
|
|
|
TraceLoggingBoolean(TRUE, "UTCReplace_AppSessionGuid"),
|
|
|
|
|
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
|
|
|
|
|
|
|
|
|
|
LExit:
|
|
|
|
|
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UINT __stdcall TelemetryLogInstallCancelCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
|
|
hr = WcaInitialize(hInstall, "TelemetryLogInstallCancelCA");
|
|
|
|
|
ExitOnFailure(hr, "Failed to initialize");
|
|
|
|
|
|
|
|
|
|
TraceLoggingWriteWrapper(
|
|
|
|
|
g_hProvider,
|
|
|
|
|
"Install_Cancel",
|
|
|
|
|
TraceLoggingWideString(get_product_version().c_str(), "Version"),
|
|
|
|
|
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
|
|
|
|
TraceLoggingBoolean(TRUE, "UTCReplace_AppSessionGuid"),
|
|
|
|
|
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
|
|
|
|
|
|
|
|
|
|
LExit:
|
|
|
|
|
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UINT __stdcall TelemetryLogInstallFailCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
|
|
hr = WcaInitialize(hInstall, "TelemetryLogInstallFailCA");
|
|
|
|
|
ExitOnFailure(hr, "Failed to initialize");
|
|
|
|
|
|
|
|
|
|
TraceLoggingWriteWrapper(
|
|
|
|
|
g_hProvider,
|
|
|
|
|
"Install_Fail",
|
|
|
|
|
TraceLoggingWideString(get_product_version().c_str(), "Version"),
|
|
|
|
|
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
|
|
|
|
TraceLoggingBoolean(TRUE, "UTCReplace_AppSessionGuid"),
|
|
|
|
|
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
|
|
|
|
|
|
|
|
|
|
LExit:
|
|
|
|
|
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UINT __stdcall TelemetryLogUninstallSuccessCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
|
|
hr = WcaInitialize(hInstall, "TelemetryLogUninstallSuccessCA");
|
|
|
|
|
ExitOnFailure(hr, "Failed to initialize");
|
|
|
|
|
|
|
|
|
|
TraceLoggingWriteWrapper(
|
|
|
|
|
g_hProvider,
|
|
|
|
|
"UnInstall_Success",
|
|
|
|
|
TraceLoggingWideString(get_product_version().c_str(), "Version"),
|
|
|
|
|
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
|
|
|
|
TraceLoggingBoolean(TRUE, "UTCReplace_AppSessionGuid"),
|
|
|
|
|
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
|
|
|
|
|
|
|
|
|
|
LExit:
|
|
|
|
|
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UINT __stdcall TelemetryLogUninstallCancelCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
|
|
hr = WcaInitialize(hInstall, "TelemetryLogUninstallCancelCA");
|
|
|
|
|
ExitOnFailure(hr, "Failed to initialize");
|
|
|
|
|
|
|
|
|
|
TraceLoggingWriteWrapper(
|
|
|
|
|
g_hProvider,
|
|
|
|
|
"UnInstall_Cancel",
|
|
|
|
|
TraceLoggingWideString(get_product_version().c_str(), "Version"),
|
|
|
|
|
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
|
|
|
|
TraceLoggingBoolean(TRUE, "UTCReplace_AppSessionGuid"),
|
|
|
|
|
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
|
|
|
|
|
|
|
|
|
|
LExit:
|
|
|
|
|
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UINT __stdcall TelemetryLogUninstallFailCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
|
|
hr = WcaInitialize(hInstall, "TelemetryLogUninstallFailCA");
|
|
|
|
|
ExitOnFailure(hr, "Failed to initialize");
|
|
|
|
|
|
|
|
|
|
TraceLoggingWriteWrapper(
|
|
|
|
|
g_hProvider,
|
|
|
|
|
"UnInstall_Fail",
|
|
|
|
|
TraceLoggingWideString(get_product_version().c_str(), "Version"),
|
|
|
|
|
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
|
|
|
|
TraceLoggingBoolean(TRUE, "UTCReplace_AppSessionGuid"),
|
|
|
|
|
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
|
|
|
|
|
|
|
|
|
|
LExit:
|
|
|
|
|
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UINT __stdcall TelemetryLogRepairCancelCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
|
|
hr = WcaInitialize(hInstall, "TelemetryLogRepairCancelCA");
|
|
|
|
|
ExitOnFailure(hr, "Failed to initialize");
|
|
|
|
|
|
|
|
|
|
TraceLoggingWriteWrapper(
|
|
|
|
|
g_hProvider,
|
|
|
|
|
"Repair_Cancel",
|
|
|
|
|
TraceLoggingWideString(get_product_version().c_str(), "Version"),
|
|
|
|
|
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
|
|
|
|
TraceLoggingBoolean(TRUE, "UTCReplace_AppSessionGuid"),
|
|
|
|
|
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
|
|
|
|
|
|
|
|
|
|
LExit:
|
|
|
|
|
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UINT __stdcall TelemetryLogRepairFailCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
|
|
hr = WcaInitialize(hInstall, "TelemetryLogRepairFailCA");
|
|
|
|
|
ExitOnFailure(hr, "Failed to initialize");
|
|
|
|
|
|
|
|
|
|
TraceLoggingWriteWrapper(
|
|
|
|
|
g_hProvider,
|
|
|
|
|
"Repair_Fail",
|
|
|
|
|
TraceLoggingWideString(get_product_version().c_str(), "Version"),
|
|
|
|
|
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
|
|
|
|
TraceLoggingBoolean(TRUE, "UTCReplace_AppSessionGuid"),
|
|
|
|
|
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
|
|
|
|
|
|
|
|
|
|
LExit:
|
|
|
|
|
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UINT __stdcall DetectPrevInstallPathCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
hr = WcaInitialize(hInstall, "DetectPrevInstallPathCA");
|
|
|
|
|
MsiSetPropertyW(hInstall, L"PREVIOUSINSTALLFOLDER", L"");
|
|
|
|
|
|
|
|
|
|
LPWSTR currentScope = nullptr;
|
|
|
|
|
hr = WcaGetProperty(L"InstallScope", ¤tScope);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (auto install_path = GetMsiPackageInstalledPath(std::wstring{currentScope} == L"perUser"))
|
|
|
|
|
{
|
|
|
|
|
MsiSetPropertyW(hInstall, L"PREVIOUSINSTALLFOLDER", install_path->data());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (...)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UINT __stdcall InstallCmdPalPackageCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
using namespace winrt::Windows::Foundation;
|
|
|
|
|
using namespace winrt::Windows::Management::Deployment;
|
|
|
|
|
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
std::wstring installationFolder;
|
|
|
|
|
|
|
|
|
|
hr = WcaInitialize(hInstall, "InstallCmdPalPackage");
|
|
|
|
|
hr = getInstallFolder(hInstall, installationFolder);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
auto msix = package::FindMsixFile(installationFolder + L"\\WinUI3Apps\\CmdPal\\", false);
|
|
|
|
|
auto dependencies = package::FindMsixFile(installationFolder + L"\\WinUI3Apps\\CmdPal\\Dependencies\\", true);
|
|
|
|
|
|
|
|
|
|
if (!msix.empty())
|
|
|
|
|
{
|
|
|
|
|
auto msixPath = msix[0];
|
|
|
|
|
|
|
|
|
|
if (!package::RegisterPackage(msixPath, dependencies))
|
|
|
|
|
{
|
|
|
|
|
Logger::error(L"Failed to install CmdPal package");
|
|
|
|
|
er = ERROR_INSTALL_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (std::exception &e)
|
|
|
|
|
{
|
|
|
|
|
std::string errorMessage{"Exception thrown while trying to install CmdPal package: "};
|
|
|
|
|
errorMessage += e.what();
|
|
|
|
|
Logger::error(errorMessage);
|
|
|
|
|
|
|
|
|
|
er = ERROR_INSTALL_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
er = er == ERROR_SUCCESS ? (SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE) : er;
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UINT __stdcall UnRegisterCmdPalPackageCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
using namespace winrt::Windows::Foundation;
|
|
|
|
|
using namespace winrt::Windows::Management::Deployment;
|
|
|
|
|
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
|
|
hr = WcaInitialize(hInstall, "UnRegisterCmdPalPackageCA");
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Packages to unregister
|
|
|
|
|
std::wstring packageToRemoveDisplayName {L"Microsoft.CommandPalette"};
|
|
|
|
|
|
|
|
|
|
if (!package::UnRegisterPackage(packageToRemoveDisplayName))
|
|
|
|
|
{
|
|
|
|
|
Logger::error(L"Failed to unregister package: " + packageToRemoveDisplayName);
|
|
|
|
|
er = ERROR_INSTALL_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (std::exception &e)
|
|
|
|
|
{
|
|
|
|
|
std::string errorMessage{"Exception thrown while trying to unregister the CmdPal package: "};
|
|
|
|
|
errorMessage += e.what();
|
|
|
|
|
Logger::error(errorMessage);
|
|
|
|
|
|
|
|
|
|
er = ERROR_INSTALL_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
er = er == ERROR_SUCCESS ? (SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE) : er;
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UINT __stdcall UnRegisterContextMenuPackagesCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
using namespace winrt::Windows::Foundation;
|
|
|
|
|
using namespace winrt::Windows::Management::Deployment;
|
|
|
|
|
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
|
|
hr = WcaInitialize(hInstall, "UnRegisterContextMenuPackagesCA"); // original func name is too long
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Packages to unregister
|
|
|
|
|
const std::vector<std::wstring> packagesToRemoveDisplayName{{L"PowerRenameContextMenu"}, {L"ImageResizerContextMenu"}, {L"FileLocksmithContextMenu"}, {L"NewPlusContextMenu"}};
|
|
|
|
|
|
|
|
|
|
for (auto const &package : packagesToRemoveDisplayName)
|
|
|
|
|
{
|
|
|
|
|
if (!package::UnRegisterPackage(package))
|
|
|
|
|
{
|
|
|
|
|
Logger::error(L"Failed to unregister package: " + package);
|
|
|
|
|
er = ERROR_INSTALL_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (std::exception &e)
|
|
|
|
|
{
|
|
|
|
|
std::string errorMessage{"Exception thrown while trying to unregister sparse packages: "};
|
|
|
|
|
errorMessage += e.what();
|
|
|
|
|
Logger::error(errorMessage);
|
|
|
|
|
|
|
|
|
|
er = ERROR_INSTALL_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
er = er == ERROR_SUCCESS ? (SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE) : er;
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UINT __stdcall CleanImageResizerRuntimeRegistryCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
hr = WcaInitialize(hInstall, "CleanImageResizerRuntimeRegistryCA");
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
const wchar_t* CLSID_STR = L"{51B4D7E5-7568-4234-B4BB-47FB3C016A69}";
|
|
|
|
|
const wchar_t* exts[] = { L".bmp", L".dib", L".gif", L".jfif", L".jpe", L".jpeg", L".jpg", L".jxr", L".png", L".rle", L".tif", L".tiff", L".wdp" };
|
|
|
|
|
|
|
|
|
|
auto deleteKeyRecursive = [](HKEY root, const std::wstring &path) {
|
|
|
|
|
RegDeleteTreeW(root, path.c_str());
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// InprocServer32 chain root CLSID
|
|
|
|
|
deleteKeyRecursive(HKEY_CURRENT_USER, L"Software\\Classes\\CLSID\\" + std::wstring(CLSID_STR));
|
|
|
|
|
// DragDrop handler
|
|
|
|
|
deleteKeyRecursive(HKEY_CURRENT_USER, L"Software\\Classes\\Directory\\ShellEx\\DragDropHandlers\\ImageResizer");
|
|
|
|
|
// Extensions
|
|
|
|
|
for (auto ext : exts)
|
|
|
|
|
{
|
|
|
|
|
deleteKeyRecursive(HKEY_CURRENT_USER, L"Software\\Classes\\SystemFileAssociations\\" + std::wstring(ext) + L"\\ShellEx\\ContextMenuHandlers\\ImageResizer");
|
|
|
|
|
}
|
|
|
|
|
// Sentinel
|
|
|
|
|
RegDeleteTreeW(HKEY_CURRENT_USER, L"Software\\Microsoft\\PowerToys\\ImageResizer");
|
|
|
|
|
}
|
|
|
|
|
catch (...)
|
|
|
|
|
{
|
|
|
|
|
er = ERROR_INSTALL_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
er = er == ERROR_SUCCESS ? (SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE) : er;
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UINT __stdcall CleanFileLocksmithRuntimeRegistryCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
hr = WcaInitialize(hInstall, "CleanFileLocksmithRuntimeRegistryCA");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
const wchar_t* CLSID_STR = L"{84D68575-E186-46AD-B0CB-BAEB45EE29C0}";
|
|
|
|
|
auto deleteKeyRecursive = [](HKEY root, const std::wstring& path) {
|
|
|
|
|
RegDeleteTreeW(root, path.c_str());
|
|
|
|
|
};
|
|
|
|
|
deleteKeyRecursive(HKEY_CURRENT_USER, L"Software\\Classes\\CLSID\\" + std::wstring(CLSID_STR));
|
|
|
|
|
deleteKeyRecursive(HKEY_CURRENT_USER, L"Software\\Classes\\AllFileSystemObjects\\ShellEx\\ContextMenuHandlers\\FileLocksmithExt");
|
|
|
|
|
deleteKeyRecursive(HKEY_CURRENT_USER, L"Software\\Classes\\Drive\\ShellEx\\ContextMenuHandlers\\FileLocksmithExt");
|
|
|
|
|
RegDeleteTreeW(HKEY_CURRENT_USER, L"Software\\Microsoft\\PowerToys\\FileLocksmith");
|
|
|
|
|
}
|
|
|
|
|
catch (...)
|
|
|
|
|
{
|
|
|
|
|
er = ERROR_INSTALL_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
er = er == ERROR_SUCCESS ? (SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE) : er;
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UINT __stdcall CleanPowerRenameRuntimeRegistryCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
hr = WcaInitialize(hInstall, "CleanPowerRenameRuntimeRegistryCA");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
const wchar_t* CLSID_STR = L"{0440049F-D1DC-4E46-B27B-98393D79486B}";
|
|
|
|
|
auto deleteKeyRecursive = [](HKEY root, const std::wstring& path) {
|
|
|
|
|
RegDeleteTreeW(root, path.c_str());
|
|
|
|
|
};
|
|
|
|
|
deleteKeyRecursive(HKEY_CURRENT_USER, L"Software\\Classes\\CLSID\\" + std::wstring(CLSID_STR));
|
|
|
|
|
deleteKeyRecursive(HKEY_CURRENT_USER, L"Software\\Classes\\AllFileSystemObjects\\ShellEx\\ContextMenuHandlers\\PowerRenameExt");
|
|
|
|
|
deleteKeyRecursive(HKEY_CURRENT_USER, L"Software\\Classes\\Directory\\background\\ShellEx\\ContextMenuHandlers\\PowerRenameExt");
|
|
|
|
|
RegDeleteTreeW(HKEY_CURRENT_USER, L"Software\\Microsoft\\PowerToys\\PowerRename");
|
|
|
|
|
}
|
|
|
|
|
catch (...)
|
|
|
|
|
{
|
|
|
|
|
er = ERROR_INSTALL_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
er = er == ERROR_SUCCESS ? (SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE) : er;
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UINT __stdcall CleanNewPlusRuntimeRegistryCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
hr = WcaInitialize(hInstall, "CleanNewPlusRuntimeRegistryCA");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
const wchar_t* CLSID_STR = L"{FF90D477-E32A-4BE8-8CC5-A502A97F5401}";
|
|
|
|
|
auto deleteKeyRecursive = [](HKEY root, const std::wstring& path) {
|
|
|
|
|
RegDeleteTreeW(root, path.c_str());
|
|
|
|
|
};
|
|
|
|
|
deleteKeyRecursive(HKEY_CURRENT_USER, L"Software\\Classes\\CLSID\\" + std::wstring(CLSID_STR));
|
|
|
|
|
deleteKeyRecursive(HKEY_CURRENT_USER, L"Software\\Classes\\Directory\\background\\ShellEx\\ContextMenuHandlers\\NewPlusShellExtensionWin10");
|
|
|
|
|
RegDeleteTreeW(HKEY_CURRENT_USER, L"Software\\Microsoft\\PowerToys\\NewPlus");
|
|
|
|
|
}
|
|
|
|
|
catch (...)
|
|
|
|
|
{
|
|
|
|
|
er = ERROR_INSTALL_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
er = er == ERROR_SUCCESS ? (SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE) : er;
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UINT __stdcall TerminateProcessesCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
hr = WcaInitialize(hInstall, "TerminateProcessesCA");
|
|
|
|
|
|
|
|
|
|
std::vector<DWORD> processes;
|
|
|
|
|
const size_t maxProcesses = 4096;
|
|
|
|
|
DWORD bytes = maxProcesses * sizeof(processes[0]);
|
|
|
|
|
processes.resize(maxProcesses);
|
|
|
|
|
|
|
|
|
|
if (!EnumProcesses(processes.data(), bytes, &bytes))
|
|
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
processes.resize(bytes / sizeof(processes[0]));
|
|
|
|
|
|
fix(shortcut-guide): prevent orphaned processes during shutdown (#50091)
## Summary of the Pull Request
Prevents Shortcut Guide processes from surviving Runner shutdown and
blocking PowerToys upgrades.
- Shuts down WinUI through its dispatcher instead of forcing CLR
termination from a worker thread.
- Opens and retains the Runner process handle before WinUI
initialization so early Runner exits cannot be missed.
- Gives the native module deterministic ownership of the Shortcut Guide
process handle, with graceful shutdown and a bounded forced-termination
fallback.
- Keeps telemetry subprocess handles separate from the persistent UI
process.
- Adds `PowerToys.ShortcutGuide.exe` to the installer termination
fallback so affected existing installations can recover during upgrade.
## PR Checklist
- [x] **Communication:** Discussed and requested by a core contributor
after investigating the release regression.
- [x] **Tests:** Existing tests pass; process lifecycle and installer
file replacement were also validated.
## Detailed Description of the Pull Request / Additional comments
The Shortcut Guide lifecycle introduced by #48683 could call
`Environment.Exit` from a Runner-watcher worker thread while WinUI was
still tearing down. The native module also overwrote its persistent
child-process handle when launching telemetry and did not close
completed handles. Repeated Runner lifetimes could therefore leave
`PowerToys.ShortcutGuide.exe` processes retaining shared WinUI files.
The installer did not recover from that state: Restart Manager is
disabled, the bundle and WiX close-application steps target only
`PowerToys.exe`, and `TerminateProcessesCA` did not include
`PowerToys.ShortcutGuide.exe`. Locked files could consequently remain at
the previous version while installation continued, producing a mixed
payload.
`src/modules/ShortcutGuide/ShortcutGuide.Ui/Program.cs` now
synchronously captures the Runner process handle and publishes its exit
through a wait handle.
`src/modules/ShortcutGuide/ShortcutGuide.Ui/ShortcutGuideXAML/App.xaml.cs`
registers that wait with the UI dispatcher, centralizes idempotent
shutdown, and disposes activation listeners and hooks deterministically.
`src/modules/ShortcutGuide/ShortcutGuideModuleInterface/dllmain.cpp` now
uses RAII for the tracked UI process, avoids replacing it with telemetry
handles, signals the existing native exit event, waits for graceful
shutdown, and terminates only as a bounded fallback. The event is
projected to managed code through `src/common/interop/Constants.idl`.
`installer/PowerToysSetupCustomActionsVNext/CustomAction.cpp` now
includes `PowerToys.ShortcutGuide.exe` in the MSI process-termination
fallback, allowing upgrades from already-affected builds.
## Validation Steps Performed
- Built `PowerToys.Interop.vcxproj`,
`ShortcutGuideModuleInterface.vcxproj`, `ShortcutGuide.Ui.csproj`, and
`PowerToysSetupCustomActionsVNext.vcxproj` for x64 Release.
- Built and ran `ShortcutGuide.UnitTests`: 48/48 passed.
- Repeated Runner/Shortcut Guide startup and parent-exit teardown 10
times; every child exited with code 0.
- Verified the race where the Runner exits before Shortcut Guide
initializes.
- Verified `PowerToys.ShortcutGuide.exe`, `PowerToys.Interop.dll`, and
`Microsoft.UI.Xaml.dll` were immediately replaceable after shutdown.
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 7f6c4822-53e0-42ae-a51a-a302a7c6d3ab
2026-08-25 13:14:32 +08:00
|
|
|
std::array<std::wstring_view, 46> processesToTerminate = {
|
[Installer] Upgrade the installer from WiX3 to WiX5 (#40877)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
Background: The current PowerToys installer is built using Wix3, which
has now been deprecated. To improve security, service quality, and
community support, we’re upgrading the installer to Wix5.
Implementation:
Created Wix5-based projects(PowerToysSetupVext and
PowerToysSetupCustomActionsVNext) within the installer while retaining
the existing Wix3 project. Both versions are built to generate separate
installation packages. The Wix3-related code will be removed after
successful release testing confirms no issues.
Special case:
Wix5 has removed the property for 'ShowFilesInUse'. Now, whenever a file
is in use during installation, a FilesInUse pop-upwill automatically
appear asking for the next step. To ensure this doesn't interfere with
scenarios that require silent installation (e.g. Winget method), we’ve
handled it using the bafunction approach.
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
- [ ] Closes: #xxx
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx
<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments
<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
---------
Co-authored-by: Jerry Xu <n.xu@outlook.com>
Co-authored-by: Kai Tao <69313318+vanzue@users.noreply.github.com>
Co-authored-by: leileizhang <leilzh@microsoft.com>
Co-authored-by: Kai Tao (from Dev Box) <kaitao@microsoft.com>
Co-authored-by: vanzue <vanzue@outlook.com>
2025-08-25 18:39:11 +08:00
|
|
|
L"PowerToys.PowerLauncher.exe",
|
|
|
|
|
L"PowerToys.Settings.exe",
|
|
|
|
|
L"PowerToys.AdvancedPaste.exe",
|
|
|
|
|
L"PowerToys.Awake.exe",
|
|
|
|
|
L"PowerToys.FancyZones.exe",
|
|
|
|
|
L"PowerToys.FancyZonesEditor.exe",
|
|
|
|
|
L"PowerToys.FileLocksmithUI.exe",
|
|
|
|
|
L"PowerToys.MouseJumpUI.exe",
|
|
|
|
|
L"PowerToys.ColorPickerUI.exe",
|
|
|
|
|
L"PowerToys.AlwaysOnTop.exe",
|
|
|
|
|
L"PowerToys.RegistryPreview.exe",
|
|
|
|
|
L"PowerToys.Hosts.exe",
|
|
|
|
|
L"PowerToys.PowerRename.exe",
|
|
|
|
|
L"PowerToys.ImageResizer.exe",
|
[New Module] Light Switch (#41987)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
This pull request introduces a new module called "Light Switch" which
allows users to automatically switch between light and dark mode on a
timer.

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
- [x] Closes: #1331
- [x] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [x] **Tests:** Added/updated and all pass
- [x] **Localization:** All end-user-facing strings can be localized
- [x] **Dev docs:** Added/updated
- [x] **New binaries:** Added on the required places
- [x] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [x] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [x] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here:
[#5867](https://github.com/MicrosoftDocs/windows-dev-docs-pr/pull/5867)
<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments
### Known bugs:
- Default settings not saving correctly when switching modes
- Issue: Sometimes when you switch from one mode to another, they are
supposed to update with new defaults but sometimes this fails for the
second variable. Potentially has to do with accessing the settings file
while another chunk of code is still updating.
- Sometimes the system looks "glitched" when switching themes
### To do:
- [x] OOBE page and assets
- [x] Logic to disable the chart when no location has been selected
- [x] Localization
### How to and what to test
Grab the latest installer from the pipeline below for your architecture
and install PowerToys from there.
- Toggle theme shortcutSystem only, Apps only, Both system and apps
selected
- Does changing the values on the settings page update the settings
file? %LOCALAPPDATA%/Microsoft/PowerToys/LightSwitch/settings.json
- Manual mode: System only, Apps only, Both system and apps selected
- Sunrise modes: Are the times accurate?
- If you manage to let this run through sunset/rise does the theme
change?
- Set your theme to change within the next minute using manual mode and
set your device to sleepOpen your device and login once the time you set
has passed. --> Do your settings resync once the next minute ticks after
logging back into your device?
- Disable the service and ensure the tasks actually ends.
- While the module is disabled:
- Make sure the shortcut no longer works
- Make sure the last time you set doesn't trigger a theme change
- Bonus: Toggle GPO Configuration and make sure you are unable to enable
the module
---------
Co-authored-by: Niels Laute <niels.laute@live.nl>
Co-authored-by: Gordon Lam (SH) <yeelam@microsoft.com>
2025-10-06 16:44:07 -04:00
|
|
|
L"PowerToys.LightSwitchService.exe",
|
2026-04-10 15:14:41 +08:00
|
|
|
L"PowerToys.PowerDisplay.exe",
|
[Installer] Upgrade the installer from WiX3 to WiX5 (#40877)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
Background: The current PowerToys installer is built using Wix3, which
has now been deprecated. To improve security, service quality, and
community support, we’re upgrading the installer to Wix5.
Implementation:
Created Wix5-based projects(PowerToysSetupVext and
PowerToysSetupCustomActionsVNext) within the installer while retaining
the existing Wix3 project. Both versions are built to generate separate
installation packages. The Wix3-related code will be removed after
successful release testing confirms no issues.
Special case:
Wix5 has removed the property for 'ShowFilesInUse'. Now, whenever a file
is in use during installation, a FilesInUse pop-upwill automatically
appear asking for the next step. To ensure this doesn't interfere with
scenarios that require silent installation (e.g. Winget method), we’ve
handled it using the bafunction approach.
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
- [ ] Closes: #xxx
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx
<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments
<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
---------
Co-authored-by: Jerry Xu <n.xu@outlook.com>
Co-authored-by: Kai Tao <69313318+vanzue@users.noreply.github.com>
Co-authored-by: leileizhang <leilzh@microsoft.com>
Co-authored-by: Kai Tao (from Dev Box) <kaitao@microsoft.com>
Co-authored-by: vanzue <vanzue@outlook.com>
2025-08-25 18:39:11 +08:00
|
|
|
L"PowerToys.GcodeThumbnailProvider.exe",
|
|
|
|
|
L"PowerToys.BgcodeThumbnailProvider.exe",
|
|
|
|
|
L"PowerToys.PdfThumbnailProvider.exe",
|
|
|
|
|
L"PowerToys.MonacoPreviewHandler.exe",
|
|
|
|
|
L"PowerToys.MarkdownPreviewHandler.exe",
|
|
|
|
|
L"PowerToys.StlThumbnailProvider.exe",
|
|
|
|
|
L"PowerToys.SvgThumbnailProvider.exe",
|
|
|
|
|
L"PowerToys.GcodePreviewHandler.exe",
|
|
|
|
|
L"PowerToys.BgcodePreviewHandler.exe",
|
|
|
|
|
L"PowerToys.QoiPreviewHandler.exe",
|
|
|
|
|
L"PowerToys.PdfPreviewHandler.exe",
|
|
|
|
|
L"PowerToys.QoiThumbnailProvider.exe",
|
|
|
|
|
L"PowerToys.SvgPreviewHandler.exe",
|
|
|
|
|
L"PowerToys.Peek.UI.exe",
|
|
|
|
|
L"PowerToys.MouseWithoutBorders.exe",
|
|
|
|
|
L"PowerToys.MouseWithoutBordersHelper.exe",
|
|
|
|
|
L"PowerToys.MouseWithoutBordersService.exe",
|
|
|
|
|
L"PowerToys.CropAndLock.exe",
|
|
|
|
|
L"PowerToys.EnvironmentVariables.exe",
|
2026-01-13 17:18:48 +08:00
|
|
|
L"PowerToys.QuickAccess.exe",
|
[Installer] Upgrade the installer from WiX3 to WiX5 (#40877)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
Background: The current PowerToys installer is built using Wix3, which
has now been deprecated. To improve security, service quality, and
community support, we’re upgrading the installer to Wix5.
Implementation:
Created Wix5-based projects(PowerToysSetupVext and
PowerToysSetupCustomActionsVNext) within the installer while retaining
the existing Wix3 project. Both versions are built to generate separate
installation packages. The Wix3-related code will be removed after
successful release testing confirms no issues.
Special case:
Wix5 has removed the property for 'ShowFilesInUse'. Now, whenever a file
is in use during installation, a FilesInUse pop-upwill automatically
appear asking for the next step. To ensure this doesn't interfere with
scenarios that require silent installation (e.g. Winget method), we’ve
handled it using the bafunction approach.
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
- [ ] Closes: #xxx
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx
<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments
<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
---------
Co-authored-by: Jerry Xu <n.xu@outlook.com>
Co-authored-by: Kai Tao <69313318+vanzue@users.noreply.github.com>
Co-authored-by: leileizhang <leilzh@microsoft.com>
Co-authored-by: Kai Tao (from Dev Box) <kaitao@microsoft.com>
Co-authored-by: vanzue <vanzue@outlook.com>
2025-08-25 18:39:11 +08:00
|
|
|
L"PowerToys.WorkspacesSnapshotTool.exe",
|
|
|
|
|
L"PowerToys.WorkspacesLauncher.exe",
|
|
|
|
|
L"PowerToys.WorkspacesLauncherUI.exe",
|
|
|
|
|
L"PowerToys.WorkspacesEditor.exe",
|
|
|
|
|
L"PowerToys.WorkspacesWindowArranger.exe",
|
|
|
|
|
L"Microsoft.CmdPal.UI.exe",
|
2026-01-13 17:18:48 +08:00
|
|
|
L"Microsoft.CmdPal.Ext.PowerToys.exe",
|
fix(shortcut-guide): prevent orphaned processes during shutdown (#50091)
## Summary of the Pull Request
Prevents Shortcut Guide processes from surviving Runner shutdown and
blocking PowerToys upgrades.
- Shuts down WinUI through its dispatcher instead of forcing CLR
termination from a worker thread.
- Opens and retains the Runner process handle before WinUI
initialization so early Runner exits cannot be missed.
- Gives the native module deterministic ownership of the Shortcut Guide
process handle, with graceful shutdown and a bounded forced-termination
fallback.
- Keeps telemetry subprocess handles separate from the persistent UI
process.
- Adds `PowerToys.ShortcutGuide.exe` to the installer termination
fallback so affected existing installations can recover during upgrade.
## PR Checklist
- [x] **Communication:** Discussed and requested by a core contributor
after investigating the release regression.
- [x] **Tests:** Existing tests pass; process lifecycle and installer
file replacement were also validated.
## Detailed Description of the Pull Request / Additional comments
The Shortcut Guide lifecycle introduced by #48683 could call
`Environment.Exit` from a Runner-watcher worker thread while WinUI was
still tearing down. The native module also overwrote its persistent
child-process handle when launching telemetry and did not close
completed handles. Repeated Runner lifetimes could therefore leave
`PowerToys.ShortcutGuide.exe` processes retaining shared WinUI files.
The installer did not recover from that state: Restart Manager is
disabled, the bundle and WiX close-application steps target only
`PowerToys.exe`, and `TerminateProcessesCA` did not include
`PowerToys.ShortcutGuide.exe`. Locked files could consequently remain at
the previous version while installation continued, producing a mixed
payload.
`src/modules/ShortcutGuide/ShortcutGuide.Ui/Program.cs` now
synchronously captures the Runner process handle and publishes its exit
through a wait handle.
`src/modules/ShortcutGuide/ShortcutGuide.Ui/ShortcutGuideXAML/App.xaml.cs`
registers that wait with the UI dispatcher, centralizes idempotent
shutdown, and disposes activation listeners and hooks deterministically.
`src/modules/ShortcutGuide/ShortcutGuideModuleInterface/dllmain.cpp` now
uses RAII for the tracked UI process, avoids replacing it with telemetry
handles, signals the existing native exit event, waits for graceful
shutdown, and terminates only as a bounded fallback. The event is
projected to managed code through `src/common/interop/Constants.idl`.
`installer/PowerToysSetupCustomActionsVNext/CustomAction.cpp` now
includes `PowerToys.ShortcutGuide.exe` in the MSI process-termination
fallback, allowing upgrades from already-affected builds.
## Validation Steps Performed
- Built `PowerToys.Interop.vcxproj`,
`ShortcutGuideModuleInterface.vcxproj`, `ShortcutGuide.Ui.csproj`, and
`PowerToysSetupCustomActionsVNext.vcxproj` for x64 Release.
- Built and ran `ShortcutGuide.UnitTests`: 48/48 passed.
- Repeated Runner/Shortcut Guide startup and parent-exit teardown 10
times; every child exited with code 0.
- Verified the race where the Runner exits before Shortcut Guide
initializes.
- Verified `PowerToys.ShortcutGuide.exe`, `PowerToys.Interop.dll`, and
`Microsoft.UI.Xaml.dll` were immediately replaceable after shutdown.
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 7f6c4822-53e0-42ae-a51a-a302a7c6d3ab
2026-08-25 13:14:32 +08:00
|
|
|
L"PowerToys.ShortcutGuide.exe",
|
[Installer] Upgrade the installer from WiX3 to WiX5 (#40877)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
Background: The current PowerToys installer is built using Wix3, which
has now been deprecated. To improve security, service quality, and
community support, we’re upgrading the installer to Wix5.
Implementation:
Created Wix5-based projects(PowerToysSetupVext and
PowerToysSetupCustomActionsVNext) within the installer while retaining
the existing Wix3 project. Both versions are built to generate separate
installation packages. The Wix3-related code will be removed after
successful release testing confirms no issues.
Special case:
Wix5 has removed the property for 'ShowFilesInUse'. Now, whenever a file
is in use during installation, a FilesInUse pop-upwill automatically
appear asking for the next step. To ensure this doesn't interfere with
scenarios that require silent installation (e.g. Winget method), we’ve
handled it using the bafunction approach.
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
- [ ] Closes: #xxx
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx
<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments
<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
---------
Co-authored-by: Jerry Xu <n.xu@outlook.com>
Co-authored-by: Kai Tao <69313318+vanzue@users.noreply.github.com>
Co-authored-by: leileizhang <leilzh@microsoft.com>
Co-authored-by: Kai Tao (from Dev Box) <kaitao@microsoft.com>
Co-authored-by: vanzue <vanzue@outlook.com>
2025-08-25 18:39:11 +08:00
|
|
|
L"PowerToys.ZoomIt.exe",
|
|
|
|
|
L"PowerToys.exe",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for (const auto procID : processes)
|
|
|
|
|
{
|
|
|
|
|
if (!procID)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
wchar_t processName[MAX_PATH] = L"<unknown>";
|
|
|
|
|
|
|
|
|
|
HANDLE hProcess{OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ | PROCESS_TERMINATE, FALSE, procID)};
|
|
|
|
|
if (!hProcess)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
HMODULE hMod;
|
|
|
|
|
DWORD cbNeeded;
|
|
|
|
|
|
|
|
|
|
if (!EnumProcessModules(hProcess, &hMod, sizeof(hMod), &cbNeeded))
|
|
|
|
|
{
|
|
|
|
|
CloseHandle(hProcess);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
GetModuleBaseNameW(hProcess, hMod, processName, sizeof(processName) / sizeof(wchar_t));
|
|
|
|
|
|
|
|
|
|
for (const auto processToTerminate : processesToTerminate)
|
|
|
|
|
{
|
|
|
|
|
if (processName == processToTerminate)
|
|
|
|
|
{
|
|
|
|
|
const DWORD timeout = 500;
|
|
|
|
|
auto windowEnumerator = [](HWND hwnd, LPARAM procIDPtr) -> BOOL
|
|
|
|
|
{
|
|
|
|
|
auto targetProcID = *reinterpret_cast<const DWORD *>(procIDPtr);
|
|
|
|
|
DWORD windowProcID = 0;
|
|
|
|
|
GetWindowThreadProcessId(hwnd, &windowProcID);
|
|
|
|
|
if (windowProcID == targetProcID)
|
|
|
|
|
{
|
|
|
|
|
DWORD_PTR _{};
|
|
|
|
|
SendMessageTimeoutA(hwnd, WM_CLOSE, 0, 0, SMTO_BLOCK, timeout, &_);
|
|
|
|
|
}
|
|
|
|
|
return TRUE;
|
|
|
|
|
};
|
|
|
|
|
EnumWindows(windowEnumerator, reinterpret_cast<LPARAM>(&procID));
|
|
|
|
|
Sleep(timeout);
|
|
|
|
|
TerminateProcess(hProcess, 0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
CloseHandle(hProcess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
Initial DSC v3 support for PowerToys (#41132)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
Tasks checklist
- [X] Implement DSC infra in PowerToys
- [X] Implement Settings DSC resource
- [X] Implement Get, Set, Test, Export, Schema
- [X] Generate manifest (DSC resource JSON)
- [X] Added Unit Tests
- [x] Add `NJsonSchema` v11.4.0 to the stream
- [x] Package the manifest files so dsc.exe can discover them
- [x] Add `PowerToys.DSC.exe` to the PATH (maybe?)
- [x] Add `InstallLocation` in the registry key so `winget configue
export` can export the PowerToys DSC resources
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
- [X] Closes: #37276
- [X] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [X] **Tests:** Added/updated and all pass
- [X] **Localization:** All end-user-facing strings can be localized
- [x] **Dev docs:** Added/updated
- [x] **New binaries:** Added on the required places
- [x] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [x] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [x] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [x] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [x] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx
<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments
<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
---------
Co-authored-by: vanzue <vanzue@outlook.com>
Co-authored-by: Kai Tao (from Dev Box) <kaitao@microsoft.com>
Co-authored-by: Leilei Zhang <leilzh@microsoft.com>
2025-09-28 00:12:51 -07:00
|
|
|
UINT __stdcall SetBundleInstallLocationCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
|
|
// Declare all variables at the beginning to avoid goto issues
|
|
|
|
|
std::wstring customActionData;
|
|
|
|
|
std::wstring installationFolder;
|
|
|
|
|
std::wstring bundleUpgradeCode;
|
|
|
|
|
std::wstring installScope;
|
|
|
|
|
bool isPerUser = false;
|
|
|
|
|
size_t pos1 = std::wstring::npos;
|
|
|
|
|
size_t pos2 = std::wstring::npos;
|
|
|
|
|
std::vector<HKEY> keysToTry;
|
|
|
|
|
|
|
|
|
|
hr = WcaInitialize(hInstall, "SetBundleInstallLocationCA");
|
|
|
|
|
ExitOnFailure(hr, "Failed to initialize");
|
|
|
|
|
|
|
|
|
|
// Parse CustomActionData: "installFolder;upgradeCode;installScope"
|
|
|
|
|
hr = getInstallFolder(hInstall, customActionData);
|
|
|
|
|
ExitOnFailure(hr, "Failed to get CustomActionData.");
|
|
|
|
|
|
|
|
|
|
pos1 = customActionData.find(L';');
|
|
|
|
|
if (pos1 == std::wstring::npos)
|
|
|
|
|
{
|
|
|
|
|
hr = E_INVALIDARG;
|
|
|
|
|
ExitOnFailure(hr, "Invalid CustomActionData format - missing first semicolon");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pos2 = customActionData.find(L';', pos1 + 1);
|
|
|
|
|
if (pos2 == std::wstring::npos)
|
|
|
|
|
{
|
|
|
|
|
hr = E_INVALIDARG;
|
|
|
|
|
ExitOnFailure(hr, "Invalid CustomActionData format - missing second semicolon");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
installationFolder = customActionData.substr(0, pos1);
|
|
|
|
|
bundleUpgradeCode = customActionData.substr(pos1 + 1, pos2 - pos1 - 1);
|
|
|
|
|
installScope = customActionData.substr(pos2 + 1);
|
|
|
|
|
|
|
|
|
|
isPerUser = (installScope == L"perUser");
|
|
|
|
|
|
|
|
|
|
// Use the appropriate registry based on install scope
|
|
|
|
|
HKEY targetKey = isPerUser ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
|
|
|
|
|
const wchar_t* keyName = isPerUser ? L"HKCU" : L"HKLM";
|
|
|
|
|
|
|
|
|
|
WcaLog(LOGMSG_STANDARD, "SetBundleInstallLocationCA: Searching for Bundle in %ls registry", keyName);
|
|
|
|
|
|
|
|
|
|
HKEY uninstallKey;
|
|
|
|
|
LONG openResult = RegOpenKeyExW(targetKey, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall", 0, KEY_READ | KEY_ENUMERATE_SUB_KEYS, &uninstallKey);
|
|
|
|
|
if (openResult != ERROR_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
WcaLog(LOGMSG_STANDARD, "SetBundleInstallLocationCA: Failed to open uninstall key, error: %ld", openResult);
|
|
|
|
|
goto LExit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DWORD index = 0;
|
|
|
|
|
wchar_t subKeyName[256];
|
|
|
|
|
DWORD subKeyNameSize = sizeof(subKeyName) / sizeof(wchar_t);
|
|
|
|
|
|
|
|
|
|
while (RegEnumKeyExW(uninstallKey, index, subKeyName, &subKeyNameSize, nullptr, nullptr, nullptr, nullptr) == ERROR_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
HKEY productKey;
|
|
|
|
|
if (RegOpenKeyExW(uninstallKey, subKeyName, 0, KEY_READ | KEY_WRITE, &productKey) == ERROR_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
wchar_t upgradeCode[256];
|
|
|
|
|
DWORD upgradeCodeSize = sizeof(upgradeCode);
|
|
|
|
|
DWORD valueType;
|
|
|
|
|
|
|
|
|
|
if (RegQueryValueExW(productKey, L"BundleUpgradeCode", nullptr, &valueType,
|
|
|
|
|
reinterpret_cast<LPBYTE>(upgradeCode), &upgradeCodeSize) == ERROR_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
// Remove brackets from registry upgradeCode for comparison (bundleUpgradeCode doesn't have brackets)
|
|
|
|
|
std::wstring regUpgradeCode = upgradeCode;
|
|
|
|
|
if (!regUpgradeCode.empty() && regUpgradeCode.front() == L'{' && regUpgradeCode.back() == L'}')
|
|
|
|
|
{
|
|
|
|
|
regUpgradeCode = regUpgradeCode.substr(1, regUpgradeCode.length() - 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_wcsicmp(regUpgradeCode.c_str(), bundleUpgradeCode.c_str()) == 0)
|
|
|
|
|
{
|
|
|
|
|
// Found matching Bundle, set InstallLocation
|
|
|
|
|
LONG setResult = RegSetValueExW(productKey, L"InstallLocation", 0, REG_SZ,
|
|
|
|
|
reinterpret_cast<const BYTE*>(installationFolder.c_str()),
|
|
|
|
|
static_cast<DWORD>((installationFolder.length() + 1) * sizeof(wchar_t)));
|
|
|
|
|
|
|
|
|
|
if (setResult == ERROR_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
WcaLog(LOGMSG_STANDARD, "SetBundleInstallLocationCA: InstallLocation set successfully");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
WcaLog(LOGMSG_STANDARD, "SetBundleInstallLocationCA: Failed to set InstallLocation, error: %ld", setResult);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RegCloseKey(productKey);
|
|
|
|
|
RegCloseKey(uninstallKey);
|
|
|
|
|
goto LExit;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
RegCloseKey(productKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
index++;
|
|
|
|
|
subKeyNameSize = sizeof(subKeyName) / sizeof(wchar_t);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RegCloseKey(uninstallKey);
|
|
|
|
|
|
|
|
|
|
LExit:
|
|
|
|
|
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
[Installer] Upgrade the installer from WiX3 to WiX5 (#40877)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
Background: The current PowerToys installer is built using Wix3, which
has now been deprecated. To improve security, service quality, and
community support, we’re upgrading the installer to Wix5.
Implementation:
Created Wix5-based projects(PowerToysSetupVext and
PowerToysSetupCustomActionsVNext) within the installer while retaining
the existing Wix3 project. Both versions are built to generate separate
installation packages. The Wix3-related code will be removed after
successful release testing confirms no issues.
Special case:
Wix5 has removed the property for 'ShowFilesInUse'. Now, whenever a file
is in use during installation, a FilesInUse pop-upwill automatically
appear asking for the next step. To ensure this doesn't interfere with
scenarios that require silent installation (e.g. Winget method), we’ve
handled it using the bafunction approach.
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
- [ ] Closes: #xxx
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx
<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments
<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
---------
Co-authored-by: Jerry Xu <n.xu@outlook.com>
Co-authored-by: Kai Tao <69313318+vanzue@users.noreply.github.com>
Co-authored-by: leileizhang <leilzh@microsoft.com>
Co-authored-by: Kai Tao (from Dev Box) <kaitao@microsoft.com>
Co-authored-by: vanzue <vanzue@outlook.com>
2025-08-25 18:39:11 +08:00
|
|
|
void initSystemLogger()
|
|
|
|
|
{
|
|
|
|
|
static std::once_flag initLoggerFlag;
|
|
|
|
|
std::call_once(initLoggerFlag, []()
|
|
|
|
|
{
|
|
|
|
|
WCHAR temp_path[MAX_PATH];
|
|
|
|
|
auto ret = GetTempPath(MAX_PATH, temp_path);
|
|
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
|
{
|
|
|
|
|
Logger::init("PowerToysMSI", std::wstring{ temp_path } + L"\\PowerToysMSIInstaller", L"");
|
|
|
|
|
} });
|
|
|
|
|
}
|
|
|
|
|
|
Remove unused dependencies and shrink installer size (#47233)
## Summary of the Pull Request
Two related installer changes to (1) eliminate genuinely-unused
dependencies and (2) deduplicate shared WinAppSDK files between
`<install>\` and `<install>\WinUI3Apps\` to shrink the installer
download.
### 1. Remove unused dependencies (~11 MB savings per output location)
- **System.Data.SqlClient**: Removed from MouseWithoutBorders projects
and the central `Directory.Packages.props` pin. It was a transitive
dependency of `Microsoft.Windows.Compatibility` but PowerToys has zero
SQL database usage.
- **Unused `using` import**: Removed `using
System.ServiceModel.Channels` from MouseWithoutBorders `Program.cs` (no
WCF usage).
- **MFC / C++ AMP / OpenMP DLLs**: Added `RemoveUnusedVCRuntimeDlls`
target in `Directory.Build.targets` to clean up `mfc140*`, `mfcm140*`,
`vcamp140*`, and `vcomp140*` DLLs that leak from the VC++
Redistributable tree but are not imported by any PowerToys binary
(verified with `dumpbin /dependents` across all installed binaries).
Also excluded MFC DLLs from installer file collection.
### 2. WinAppSDK file deduplication (build-time only; install-time uses
copy)
**Background**: The `WinUI3Apps` subfolder must remain a real directory
because MSIX sparse package registration applies DACL changes to the
`ExternalLocation` folder (PR #47177). Flattening is not viable.
**Build-time** (`generateAllFileComponents.ps1`): computes the SHA256
intersection of root and `WinUI3Apps` files, and for each file that is
also present in the BaseApplications WXS file list, removes the
duplicate from the WinUI3Apps WXS component list and writes its name to
a `hardlinks.txt` manifest. The BaseApplications cross-check ensures we
never deduplicate a file the MSI does not actually deploy at the install
root, which would otherwise leave both copies missing post-install. The
manifest is written as UTF-8 without BOM (via
`[System.IO.File]::WriteAllLines` with `UTF8Encoding($false)`) so its
encoding is identical regardless of the build host's PowerShell version.
This step produces the **MSI download-size win** (~97 MB smaller cab;
LZX:21 was already deduplicating most byte-identical content
automatically inside the cab).
**Install-time** (`CreateWinAppSDKHardlinksCA` custom action):
- Reads `hardlinks.txt` after `InstallFiles` as a raw byte stream and
converts each line to a `std::wstring` via `MultiByteToWideChar(CP_UTF8,
MB_ERR_INVALID_CHARS, ...)`. Avoids `std::wifstream`'s ANSI-codepage
codecvt so non-ASCII paths can never be silently mangled.
- For each entry, computes `(installDir / fileName).lexically_normal()`
and `(winui3Dir / fileName).lexically_normal()`, then verifies via
`std::mismatch` that each resolved path is still rooted at its
respective folder. Manifest entries containing `..`, absolute paths, or
alternate-stream syntax are logged and skipped.
- Materialises each validated entry from `<install>\<name>` into
`<install>\WinUI3Apps\<name>` via `fs::copy_file` (overwrite_existing).
- Reports the per-file copy / failure counts to the install log. If
every entry failed (`created == 0 && failed > 0`), the CA escalates to
`E_FAIL` so the install does not silently succeed with an unusable
WinUI3Apps tree.
`DeleteWinAppSDKHardlinksCA` removes the materialised copies before
`RemoveFiles` on uninstall, using the same UTF-8 reader and per-entry
containment check.
**WiX sequencing**: `CreateWinAppSDKHardlinks` runs
`After="InstallFiles"` with `Condition="NOT Installed OR
WIX_UPGRADE_DETECTED OR REINSTALL"` so a `msiexec /fa` repair refreshes
the deduplicated copies (otherwise `RemoveFiles` would orphan them).
#### Why copy and not hard-link
A hard-linked variant of this CA was originally proposed but caused a
Monaco preview-handler regression. Hard-links share an NTFS inode (and
therefore one DACL) between `<install>\<file>` and
`<install>\WinUI3Apps\<file>`. The MSIX sparse-package registrations for
PowerRename / ImageResizer / FileLocksmith / NewPlus run after the dedup
CA and propagate the `WinUI3Apps` parent's rich DACL (Capability SID, 5×
Package SIDs, 5× conditional SYSAPPID ACE, RC SID) onto the shared
inode. The root path then also exposes the rich DACL, which trips a
kernel "stricter access evaluation" path that blocks the LOW-IL
`prevhost.exe` from `LoadLibrary`-ing `hostfxr.dll` (and the rest of the
.NET runtime), turning the Monaco preview pane blank for `.json` / `.md`
/ `.cs` / `.xaml` / `.svg` / `.xml` files.
`fs::copy_file` creates a **fresh inode** for the WinUI3Apps copy. The
root inode keeps its simple DACL (`SY:F + BA:F + owner:F` + inherited
`BU:RX`) so LOW-IL `prevhost.exe` can still load it — Monaco preview
works. The WinUI3Apps copy inherits the WinUI3Apps parent's rich DACL
via normal NTFS inheritance (matches 0.99.1 behaviour exactly) — MSIX
context-menu shells continue to work.
#### Trade-off
| Metric | Hard-link variant (rejected) | This PR (file copy) | 0.99.1
(no dedup) |
|---|---|---|---|
| MSI size | ~296 MB | ~296 MB | ~393 MB |
| On-disk after install | ~2,475 MB | ~2,772 MB | ~2,772 MB |
| DACL contamination risk | YES (broke Monaco) | NO | NO |
The on-disk savings (~297 MB) are given up in exchange for eliminating
the DACL contamination risk; the **installer download savings (~97 MB)**
are preserved by the build-time WiX/cab dedup.
#### Edge cases handled
- Empty duplicate list: `hardlinks.txt` always written, CA handles
empty.
- All files duplicated: `Generate-FileComponents` returns early for
empty list.
- File stripped from BaseApplications by an earlier build step:
BaseApplications cross-check skips it during dedup so neither copy goes
missing.
- Manifest entry escapes install root (`..`, absolute path): rejected
per-entry, install continues.
- Manifest line is non-UTF-8: rejected per-entry, install continues.
- Source missing at install time: per-entry skip, install continues.
- All copies fail: install aborts loudly via `E_FAIL` (catastrophic-case
escalation).
- Upgrade or `msiexec /fa` repair: CA fires (`NOT Installed OR
WIX_UPGRADE_DETECTED OR REINSTALL`).
**MSI repair risk**: Burn bundle uses `SuppressRepair=yes` and
`MajorUpgrade` (full uninstall + reinstall) for all version upgrades, so
the standard upgrade path is unaffected. The `OR REINSTALL` clause
covers power users running `msiexec /fa` directly.
## PR Checklist
- [x] **Communication:** Discussed approach via PRs #46866, #47177,
#46745
- [ ] **Tests:** Installer infrastructure only — no runtime behaviour
changes
- [ ] **Localization:** N/A
- [ ] **Dev docs:** N/A
- [ ] **New binaries:** N/A
## Detailed Description of the Pull Request / Additional comments
Based on the approach from PR #46745 by @yeelam-gordon, rebased onto
latest main and switched from hard-links to file copies after the DACL
contamination root cause was identified. Hardening (UTF-8 read, path
containment, catastrophic-case escalation, REINSTALL repair,
BaseApplications-filtered dedup) added in response to review feedback.
These changes are purely build/installer infrastructure — no runtime
behaviour changes to any PowerToys module.
## Validation Steps Performed
Validated on a 0.99.4 / 0.99.5 local install (per-user
`%LocalAppData%\PowerToys`):
- ✅ `dumpbin /dependents` across the installed PowerToys tree confirmed
zero binaries import `mfc140*`, `mfcm140*`, `vcamp140*`, or `vcomp140*`
— the cleanup target removes ~11 MB of genuinely unused VC runtime DLLs.
- ✅ `System.Data.SqlClient` has zero call-sites in PowerToys source.
- ✅ Local installer build produces a 296 MB MSI (down from 393 MB
pre-dedup, ~97 MB cab savings purely from the build-time WiX dedup).
- ✅ MSI table inspection (`wix msi decompile`) confirms the deferred CAs
are present (`CreateWinAppSDKHardlinks`, `DeleteWinAppSDKHardlinks`) and
the `hardlinks.txt` File row is registered.
- ✅ MSI table inspection confirms .NET runtime DLLs (`hostfxr.dll`,
`coreclr.dll`, `hostpolicy.dll`, `clretwrc.dll`, `Accessibility.dll`,
`backup_restore_settings.json`) appear ONLY in
`BaseApplicationsFiles_File_*`, NOT in `WinUI3ApplicationsFiles_File_*`
— proving the build-time dedup worked.
- ✅ Post-install verification: deduplicated files materialised at both
root and WinUI3Apps with byte-identical SHA256 hashes, and `fsutil
hardlink list` returns link-count == 1 for each — proving the
install-time copy approach worked, not hard-link.
- ✅ DACL on root .NET runtime DLLs is clean: no Package SID, no
Capability SID, no SYSAPPID conditional ACE, no `ALL APPLICATION
PACKAGES` ACE — Monaco preview load path is safe.
- ✅ DACL on WinUI3Apps copies has the rich MSIX inheritance —
context-menu shells continue to work (matches 0.99.1).
- ✅ All four MSIX sparse packages (PowerRename, ImageResizer,
FileLocksmith, NewPlus) registered after install.
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-15 17:15:11 +08:00
|
|
|
// Naming note: the *Hardlinks* names in this CA, the matching WiX CustomAction Ids
|
|
|
|
|
// in Product.wxs, and the manifest filename "hardlinks.txt" are kept for continuity
|
|
|
|
|
// with the original PR design. The implementation uses fs::copy_file -- not
|
|
|
|
|
// CreateHardLinkW -- because hard-links share an inode (and DACL) between root and
|
|
|
|
|
// WinUI3Apps, which lets MSIX sparse-package registration propagate a rich DACL onto
|
|
|
|
|
// the root copy of files like hostfxr.dll and break LOW-IL prevhost.exe loads,
|
|
|
|
|
// turning the Monaco preview pane blank. Copies create a fresh inode in WinUI3Apps so the root
|
|
|
|
|
// copy keeps its simple DACL. See the in-body comment for the full RCA reference.
|
|
|
|
|
UINT __stdcall CreateWinAppSDKHardlinksCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
std::wstring installationFolder;
|
|
|
|
|
|
|
|
|
|
hr = WcaInitialize(hInstall, "CreateWinAppSDKHardlinks");
|
|
|
|
|
ExitOnFailure(hr, "Failed to initialize");
|
|
|
|
|
hr = getInstallFolder(hInstall, installationFolder);
|
|
|
|
|
ExitOnFailure(hr, "Failed to get installFolder.");
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
|
const fs::path installDir(installationFolder);
|
|
|
|
|
const fs::path winui3Dir = installDir / L"WinUI3Apps";
|
|
|
|
|
const fs::path manifestPath = winui3Dir / L"hardlinks.txt";
|
|
|
|
|
|
|
|
|
|
if (!fs::exists(manifestPath))
|
|
|
|
|
{
|
|
|
|
|
WcaLog(LOGMSG_STANDARD, "CreateWinAppSDKHardlinks: No hardlinks.txt manifest found, skipping.");
|
|
|
|
|
goto LExit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::ifstream manifestFile(manifestPath); // Read as bytes, then convert UTF-8 -> wide explicitly.
|
|
|
|
|
std::string narrowLine;
|
|
|
|
|
int created = 0;
|
|
|
|
|
int failed = 0;
|
|
|
|
|
|
|
|
|
|
// INSTALLFOLDER from MSI typically arrives with a trailing backslash. lexically_normal
|
|
|
|
|
// preserves that as an empty trailing path component, which would later make the
|
|
|
|
|
// per-component std::mismatch containment check below reject every legitimate entry.
|
|
|
|
|
// Strip any trailing separators before normalizing.
|
|
|
|
|
auto stripTrailingSep = [](fs::path p) {
|
|
|
|
|
auto s = p.native();
|
|
|
|
|
while (s.size() > 1 && (s.back() == L'\\' || s.back() == L'/')) s.pop_back();
|
|
|
|
|
return fs::path(s);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Normalize once so the per-line containment check below is cheap.
|
|
|
|
|
const fs::path installDirNorm = stripTrailingSep(installDir).lexically_normal();
|
|
|
|
|
const fs::path winui3DirNorm = stripTrailingSep(winui3Dir).lexically_normal();
|
|
|
|
|
|
|
|
|
|
while (std::getline(manifestFile, narrowLine))
|
|
|
|
|
{
|
|
|
|
|
if (narrowLine.empty())
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
// Strip CR if the manifest uses CRLF line endings.
|
|
|
|
|
if (narrowLine.back() == '\r')
|
|
|
|
|
{
|
|
|
|
|
narrowLine.pop_back();
|
|
|
|
|
if (narrowLine.empty()) continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Manifest is written as UTF-8 (no BOM) -- convert to wide string explicitly
|
|
|
|
|
// rather than relying on the locale-default codecvt of std::wifstream, which is
|
|
|
|
|
// the ANSI code page on Windows and would silently mangle any non-ASCII path.
|
|
|
|
|
const int wideLen = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, narrowLine.c_str(), -1, nullptr, 0);
|
|
|
|
|
if (wideLen <= 0)
|
|
|
|
|
{
|
|
|
|
|
WcaLog(LOGMSG_STANDARD, "CreateWinAppSDKHardlinks: Skipping non-UTF-8 entry: %hs", narrowLine.c_str());
|
|
|
|
|
failed++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
std::wstring fileName(static_cast<size_t>(wideLen) - 1, L'\0');
|
|
|
|
|
MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, narrowLine.c_str(), -1, fileName.data(), wideLen);
|
|
|
|
|
|
|
|
|
|
// Defense-in-depth: reject manifest entries that would escape the install root
|
|
|
|
|
// via "..", absolute paths, or alternate stream syntax. lexically_normal collapses
|
|
|
|
|
// any "." / ".." / repeated separators, then std::mismatch verifies the resolved
|
|
|
|
|
// path is still rooted at installDir / winui3Dir respectively.
|
|
|
|
|
const fs::path source = (installDir / fileName).lexically_normal();
|
|
|
|
|
const fs::path target = (winui3Dir / fileName).lexically_normal();
|
|
|
|
|
const auto sourceIn = std::mismatch(installDirNorm.begin(), installDirNorm.end(), source.begin(), source.end());
|
|
|
|
|
const auto targetIn = std::mismatch(winui3DirNorm.begin(), winui3DirNorm.end(), target.begin(), target.end());
|
|
|
|
|
if (sourceIn.first != installDirNorm.end() || targetIn.first != winui3DirNorm.end())
|
|
|
|
|
{
|
|
|
|
|
WcaLog(LOGMSG_STANDARD, "CreateWinAppSDKHardlinks: Rejecting entry outside install root: %ls", fileName.c_str());
|
|
|
|
|
failed++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!fs::exists(source))
|
|
|
|
|
{
|
|
|
|
|
WcaLog(LOGMSG_STANDARD, "CreateWinAppSDKHardlinks: Source not found: %ls", source.c_str());
|
|
|
|
|
failed++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Remove existing file if present (leftover from previous install)
|
|
|
|
|
std::error_code ec;
|
|
|
|
|
fs::remove(target, ec);
|
|
|
|
|
|
|
|
|
|
// Use a regular file copy (not a hard-link). Hard-links share an
|
|
|
|
|
// NTFS inode -- and therefore one DACL -- between root and
|
|
|
|
|
// WinUI3Apps, which lets MSIX sparse-package registration
|
|
|
|
|
// propagate the WinUI3Apps parent's rich (Capability/Package SID)
|
|
|
|
|
// DACL onto the root path. That trips a kernel "stricter access
|
|
|
|
|
// evaluation" path that blocks LOW-IL prevhost.exe from loading
|
|
|
|
|
// hostfxr.dll, so File Explorer Monaco preview goes blank on
|
|
|
|
|
// Windows 11 23H2. Copying creates a fresh inode in WinUI3Apps,
|
|
|
|
|
// so the root copy keeps its simple DACL while the WinUI3Apps
|
|
|
|
|
// copy inherits the rich DACL from its parent (matches 0.99.1
|
|
|
|
|
// behaviour). See Documents\PR-47233-Handoff.md for full RCA.
|
|
|
|
|
fs::copy_file(source, target, fs::copy_options::overwrite_existing, ec);
|
|
|
|
|
if (ec)
|
|
|
|
|
{
|
|
|
|
|
WcaLog(LOGMSG_STANDARD, "CreateWinAppSDKHardlinks: Failed to copy: %ls (%hs)", fileName.c_str(), ec.message().c_str());
|
|
|
|
|
failed++;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
created++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WcaLog(LOGMSG_STANDARD, "CreateWinAppSDKHardlinks: Copied %d files, %d failures", created, failed);
|
|
|
|
|
|
|
|
|
|
// Catastrophic-case escalation: if every copy failed, the WinUI3Apps tree is
|
|
|
|
|
// unusable (Monaco preview / context-menu shells will break). Surface this rather
|
|
|
|
|
// than reporting install success. Per-file failures remain tolerated.
|
|
|
|
|
if (created == 0 && failed > 0)
|
|
|
|
|
{
|
|
|
|
|
hr = E_FAIL;
|
|
|
|
|
ExitOnFailure(hr, "All WinAppSDK file copies failed; aborting install.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LExit:
|
|
|
|
|
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UINT __stdcall DeleteWinAppSDKHardlinksCA(MSIHANDLE hInstall)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
UINT er = ERROR_SUCCESS;
|
|
|
|
|
std::wstring installationFolder;
|
|
|
|
|
|
|
|
|
|
hr = WcaInitialize(hInstall, "DeleteWinAppSDKHardlinks");
|
|
|
|
|
ExitOnFailure(hr, "Failed to initialize");
|
|
|
|
|
hr = getInstallFolder(hInstall, installationFolder);
|
|
|
|
|
ExitOnFailure(hr, "Failed to get installFolder.");
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
|
const fs::path winui3Dir = fs::path(installationFolder) / L"WinUI3Apps";
|
|
|
|
|
const fs::path manifestPath = winui3Dir / L"hardlinks.txt";
|
|
|
|
|
|
|
|
|
|
if (!fs::exists(manifestPath))
|
|
|
|
|
{
|
|
|
|
|
goto LExit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::ifstream manifestFile(manifestPath); // Read as bytes; convert UTF-8 -> wide explicitly.
|
|
|
|
|
std::string narrowLine;
|
|
|
|
|
|
|
|
|
|
// INSTALLFOLDER from MSI typically arrives with a trailing backslash; strip it before
|
|
|
|
|
// normalizing so the per-line containment check doesn't false-reject every entry.
|
|
|
|
|
auto stripTrailingSep = [](fs::path p) {
|
|
|
|
|
auto s = p.native();
|
|
|
|
|
while (s.size() > 1 && (s.back() == L'\\' || s.back() == L'/')) s.pop_back();
|
|
|
|
|
return fs::path(s);
|
|
|
|
|
};
|
|
|
|
|
const fs::path winui3DirNorm = stripTrailingSep(winui3Dir).lexically_normal();
|
|
|
|
|
|
|
|
|
|
while (std::getline(manifestFile, narrowLine))
|
|
|
|
|
{
|
|
|
|
|
if (narrowLine.empty())
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (narrowLine.back() == '\r')
|
|
|
|
|
{
|
|
|
|
|
narrowLine.pop_back();
|
|
|
|
|
if (narrowLine.empty()) continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const int wideLen = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, narrowLine.c_str(), -1, nullptr, 0);
|
|
|
|
|
if (wideLen <= 0)
|
|
|
|
|
{
|
|
|
|
|
WcaLog(LOGMSG_STANDARD, "DeleteWinAppSDKHardlinks: Skipping non-UTF-8 entry: %hs", narrowLine.c_str());
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
std::wstring fileName(static_cast<size_t>(wideLen) - 1, L'\0');
|
|
|
|
|
MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, narrowLine.c_str(), -1, fileName.data(), wideLen);
|
|
|
|
|
|
|
|
|
|
// Defense-in-depth: reject entries whose resolved target escapes WinUI3Apps.
|
|
|
|
|
const fs::path target = (winui3Dir / fileName).lexically_normal();
|
|
|
|
|
const auto inWinui3 = std::mismatch(winui3DirNorm.begin(), winui3DirNorm.end(), target.begin(), target.end());
|
|
|
|
|
if (inWinui3.first != winui3DirNorm.end())
|
|
|
|
|
{
|
|
|
|
|
WcaLog(LOGMSG_STANDARD, "DeleteWinAppSDKHardlinks: Rejecting entry outside WinUI3Apps: %ls", fileName.c_str());
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::error_code ec;
|
|
|
|
|
fs::remove(target, ec);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WcaLog(LOGMSG_STANDARD, "DeleteWinAppSDKHardlinks: Cleaned up deduplicated copy files");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LExit:
|
|
|
|
|
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
|
|
|
|
|
return WcaFinalize(er);
|
|
|
|
|
}
|
|
|
|
|
|
[Installer] Upgrade the installer from WiX3 to WiX5 (#40877)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
Background: The current PowerToys installer is built using Wix3, which
has now been deprecated. To improve security, service quality, and
community support, we’re upgrading the installer to Wix5.
Implementation:
Created Wix5-based projects(PowerToysSetupVext and
PowerToysSetupCustomActionsVNext) within the installer while retaining
the existing Wix3 project. Both versions are built to generate separate
installation packages. The Wix3-related code will be removed after
successful release testing confirms no issues.
Special case:
Wix5 has removed the property for 'ShowFilesInUse'. Now, whenever a file
is in use during installation, a FilesInUse pop-upwill automatically
appear asking for the next step. To ensure this doesn't interfere with
scenarios that require silent installation (e.g. Winget method), we’ve
handled it using the bafunction approach.
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
- [ ] Closes: #xxx
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx
<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments
<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
---------
Co-authored-by: Jerry Xu <n.xu@outlook.com>
Co-authored-by: Kai Tao <69313318+vanzue@users.noreply.github.com>
Co-authored-by: leileizhang <leilzh@microsoft.com>
Co-authored-by: Kai Tao (from Dev Box) <kaitao@microsoft.com>
Co-authored-by: vanzue <vanzue@outlook.com>
2025-08-25 18:39:11 +08:00
|
|
|
// DllMain - Initialize and cleanup WiX custom action utils.
|
|
|
|
|
extern "C" BOOL WINAPI DllMain(__in HINSTANCE hInst, __in ULONG ulReason, __in LPVOID)
|
|
|
|
|
{
|
|
|
|
|
switch (ulReason)
|
|
|
|
|
{
|
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
|
WcaGlobalInitialize(hInst);
|
|
|
|
|
initSystemLogger();
|
|
|
|
|
TraceLoggingRegister(g_hProvider);
|
|
|
|
|
DLL_HANDLE = hInst;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DLL_PROCESS_DETACH:
|
|
|
|
|
TraceLoggingUnregister(g_hProvider);
|
|
|
|
|
WcaGlobalFinalize();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|