Skip to content

Commit 5802d3a

Browse files
committed
Add function to retrieve path and use it to only return file name rather than full path
1 parent 556ebc9 commit 5802d3a

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

src/AppInstallerSharedLib/Filesystem.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,4 +497,16 @@ namespace AppInstaller::Filesystem
497497

498498
return result;
499499
}
500+
501+
std::filesystem::path GetExecutablePathForProcess(HANDLE process)
502+
{
503+
wil::unique_cotaskmem_string imageName = nullptr;
504+
if (SUCCEEDED(wil::QueryFullProcessImageNameW(process, 0, imageName)) &&
505+
(imageName.get() != nullptr))
506+
{
507+
return imageName.get();
508+
}
509+
510+
return {};
511+
}
500512
}

src/AppInstallerSharedLib/Public/winget/Filesystem.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,7 @@ namespace AppInstaller::Filesystem
119119
// Gets the PathDetails used for the given path.
120120
// This is exposed primarily to allow for testing, GetPathTo should be preferred.
121121
PathDetails GetPathDetailsFor(PathName path, bool forDisplay = false);
122+
123+
// Gets the path to the executable for the given process id.
124+
std::filesystem::path GetExecutablePathForProcess(HANDLE process);
122125
}

src/Microsoft.Management.Deployment/Helpers.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <winrt/Windows.Security.Authorization.AppCapabilityAccess.h>
77
#include <appmodel.h>
88
#include <Helpers.h>
9+
#include <winget/Filesystem.h>
910
#include <winget/Security.h>
1011
#include <AppInstallerRuntime.h>
1112

@@ -144,11 +145,10 @@ namespace winrt::Microsoft::Management::Deployment::implementation
144145
}
145146

146147
// if the caller doesn't have an AppUserModelID then fall back to the executable name
147-
wil::unique_cotaskmem_string imageName = nullptr;
148-
if (SUCCEEDED(wil::QueryFullProcessImageNameW(processHandle.get(), 0, imageName)) &&
149-
(imageName.get() != nullptr))
148+
std::filesystem::path executablePath = AppInstaller::Filesystem::GetExecutablePathForProcess(processHandle.get());
149+
if (executablePath.has_filename())
150150
{
151-
return imageName.get();
151+
return executablePath.filename();
152152
}
153153
}
154154

0 commit comments

Comments
 (0)