Search code examples
c++windowspathstartmenu

Get path to all users' start menu on Windows


I am looking for a way to retrieve the path to the all users start menu directory in C++. I am only able to get the one of the current user (using Qt):

QString startMenuPath = QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation).at(0);

However, Qt does not allow to retrieve the one for all users. As far as I know there also is no environment variable containing that path, that I could read.


Solution

  • To get a known folder, use SHGetFolderPath, and pass a KNOWNFOLDERID or CSIDL for the desired folder.

    For example, the following code gets the All Users Start Menu and the Programs folder:

    // Remember to #include <Shlobj.h>
    
    WCHAR path[MAX_PATH];
    
    HRESULT hr = SHGetFolderPathW(NULL, CSIDL_COMMON_PROGRAMS, NULL, 0, path);
    if (SUCCEEDED(hr))
        std::wcout << L"Start Menu\Programs: " << path << std::endl;
    
    hr = SHGetFolderPathW(NULL, CSIDL_COMMON_STARTMENU, NULL, 0, path);
    if (SUCCEEDED(hr))
        std::wcout << L"Start Menu: " << path << std::endl;