Skip to content

ShellExecuteEx that invokes a handler that uses DelegateExecute always fails #6104

@3nthusia5t

Description

@3nthusia5t

Relevant area(s)

WinGet CLI

Relevant command(s)

winget install

Brief description of your issue

            AICLI_LOG(CLI, Info, << "Starting: '" << filePath.u8string() << "' with arguments '" << args << '\'');

            SHELLEXECUTEINFOW execInfo = { 0 };
            execInfo.cbSize = sizeof(execInfo);
            execInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
            execInfo.lpFile = filePath.c_str();
            std::wstring argsUtf16 = Utility::ConvertToUTF16(args);
            execInfo.lpParameters = argsUtf16.c_str();
            execInfo.nShow = show;

            // This installer must be run elevated, but we are not currently.
            // Have ShellExecute elevate the installer since it won't do so itself.
            if (useRunAs)
            {
                execInfo.lpVerb = L"runas";
            }

            THROW_LAST_ERROR_IF(!ShellExecuteExW(&execInfo) || !execInfo.hProcess);

            wil::unique_process_handle process{ execInfo.hProcess };

Windows shell verb registration allows a developer to intercept launching an executable and instead delegate the "Open" or "Runas" action to a COM object. Such delegation results in hProcess being NULL and results in error.

I'm not sure whether the delegation was purposefuly handled this way, but it feels like the delegation process should be responsible for reporting the feedback.

Steps to reproduce

Register any COM object and shell verb registration for "runas".

Then run:
winget install --id Microsoft.PowerShell --source winget

Expected behavior

It is my opinion, but I would not expect error message.
It's worth noting that we will be unable to wait till process finish, so we cannot tell if installation was successful.

Actual behavior

Error appearing.

PS D:\Users\admin> winget install --id Microsoft.PowerShell --source winget
Found an existing package already installed. Trying to upgrade the installed package...
Found PowerShell [Microsoft.PowerShell] Version 7.6.0.0
This application is licensed to you by its owner.
Microsoft is not responsible for, nor does it grant any licenses to, third-party packages.
Downloading https://github.com/PowerShell/PowerShell/releases/download/v7.6.0/PowerShell-7.6.0-win-x64.msi
  ██████████████████████████████   109 MB /  109 MB
Successfully verified installer hash
Starting package install...
An unexpected error occurred while executing the command:
0x8007029c : An assertion failure has occurred.

Environment

PS D:\Users\admin> winget --info
Windows Package Manager v1.28.220
Copyright (c) Microsoft Corporation. All rights reserved.

Windows: Windows.Desktop v10.0.26200.8037
System Architecture: X64
Package: Microsoft.DesktopAppInstaller v1.28.220.0

Winget Directories
-----------------------------------------------------------------------------------------------------------------------
Logs                               %LOCALAPPDATA%\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\Diag…
User Settings                      %LOCALAPPDATA%\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\sett…
Portable Links Directory (User)    %LOCALAPPDATA%\Microsoft\WinGet\Links
Portable Links Directory (Machine) C:\Program Files\WinGet\Links
Portable Package Root (User)       %LOCALAPPDATA%\Microsoft\WinGet\Packages
Portable Package Root              C:\Program Files\WinGet\Packages
Portable Package Root (x86)        C:\Program Files (x86)\WinGet\Packages
Installer Downloads                %USERPROFILE%\Downloads
Configuration Modules              %LOCALAPPDATA%\Microsoft\WinGet\Configuration\Modules

Links
---------------------------------------------------------------------------
Privacy Statement   https://aka.ms/winget-privacy
License Agreement   https://aka.ms/winget-license
Third Party Notices https://aka.ms/winget-3rdPartyNotice
Homepage            https://aka.ms/winget
Windows Store Terms https://www.microsoft.com/en-us/storedocs/terms-of-sale

Admin Setting                             State
--------------------------------------------------
LocalManifestFiles                        Disabled
BypassCertificatePinningForMicrosoftStore Disabled
InstallerHashOverride                     Disabled
LocalArchiveMalwareScanOverride           Disabled
ProxyCommandLineOptions                   Disabled
DefaultProxy                              Disabled

Metadata

Metadata

Assignees

No one assigned

    Labels

    Command-InstallIssue related to WinGet InstallIssue-BugIt either shouldn't be doing this or needs an investigation.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions