From C++, as for moment of writing this, Microsoft encourages to use SHGetKnownFolderPath
with desired value of KNOWNFOLDERID
enum. The value you need to use is FOLDERID_CommonStartMenu
. In your case, the code would look like:
wchar_t * path = nullptr;
const auto result = SHGetKnownFolderPath(FOLDERID_CommonStartMenu, 0, NULL, &path);
if (S_OK == result)
{
// do what you want with path, f.ex. create string from it
std::wstring pathAsString(path);
// according to documentation, calling process is responsible for freeing this resource
CoTaskMemFree(path);
}
Reference of SHGetKnownFolderPath
is there:
https://msdn.microsoft.com/en-us/library/windows/desktop/bb762188(v=vs.85).aspx
Reference of all available values of enum KNOWNFOLDERID
is there:
https://msdn.microsoft.com/en-us/library/windows/desktop/dd378457(v=vs.85).aspx
Info, that calling process is responsible for freeing resource, can be found in documentation of SHGetKnownFolderPath
in part documenting ppszPath
parameter.
Please note, that when it is executed from service, some values are not available (for example related to data of user, f.ex. FOLDERID_Documents
). Moreover, if some values are not available if you are using different architecture (f.ex. value related to FOLDERID_ProgramFilesX64
is not available on 32-bit operating system).
If somebody is willing to know where Microsoft encourages to use SHGetKnownFolderPath
instead of other available functions, please read top of documentation of deprecated SHGetFolderPath
.