-2

I want to store the executable name without the directory (i.e. system.exe).

How can I do this?

HANDLE Handle = OpenProcess(PROCESS_ALL_ACCESS, 0, ProcessID);
if (GetModuleFileNameEx(Handle, 0, (LPWSTR)exename, sizeof(exename) - 1))
{
   ProcessName = (wchar*)exename; // I want to store only the executable name without "C:\\..."
}
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055

1 Answers1

1

Did you search MSDN? There you can find the functions PathFindFileName and PathFindExtension that you can utilize to build your file name.

Wum
  • 306
  • 1
  • 10
  • thank you but i am getting linking error LNK2019 unresolved external symbol __imp__PathFindExtensionW@4 referenced in function _main Test – Something else May 02 '17 at 09:48
  • 1
    @Somethingelse: Right, so link the library. Its name is told to you right there on the documentation page. Shlwapi.lib. – Lightness Races in Orbit May 02 '17 at 10:07
  • The `MAX_PATH` length limitation of those shell utility functions is of limited utility. The [](https://msdn.microsoft.com/en-us/library/hh874694.aspx) implementation of Visual Studio 2015 and above may be a better match. – IInspectable May 02 '17 at 10:35