Skip to content

Instantly share code, notes, and snippets.

@lyf-is-coding
Last active October 10, 2022 16:30
Show Gist options
  • Save lyf-is-coding/75cf7438ce13a90738827dbbbe971f16 to your computer and use it in GitHub Desktop.
Save lyf-is-coding/75cf7438ce13a90738827dbbbe971f16 to your computer and use it in GitHub Desktop.
C++ Get installed steam games using WinReg library
std::vector<Game> GetInstalledSteamGames()
{
try
{
const std::wstring STEAM_INSTALLED_GAMES_KEY = L"Software\\Valve\\Steam\\Apps\\";
// Get list of user's steam games
winreg::RegKey installed_games_key{ HKEY_CURRENT_USER, STEAM_INSTALLED_GAMES_KEY };
std::vector<std::wstring> subKeyNames = installed_games_key.EnumSubKeys();
installed_games_key.Close();
std::vector<Game> steam_installed_games;
// Find all installed games
for (const std::wstring& game_id_key : subKeyNames)
{
winreg::RegKey key{ HKEY_CURRENT_USER, STEAM_INSTALLED_GAMES_KEY + game_id_key };
// Skip if not found Installed value or Installed value != 1 ( Not installed)
if (auto is_installed = key.TryGetDwordValue( L"Installed" );
!is_installed.IsValid() || is_installed.GetValue() != 1)
{
key.Close();
continue;
}
if (auto name_key_value = key.TryGetStringValue( L"Name" );
name_key_value.IsValid())
{
std::string game_name( name_key_value.GetValue().begin(), name_key_value.GetValue().end() );
steam_installed_games.emplace_back( game_name, std::stoi( game_id_key ) );
}
key.Close();
}
return steam_installed_games;
}
catch (const winreg::RegException& e)
{
/*wcout << L"\n*** Registry Exception: " << e.what();
wcout << L"\n*** [Windows API error code = " << e.code() << L"]\n\n";*/
return { };
}
catch (const std::exception& e)
{
//wcout << L"\n*** ERROR: " << e.what() << L'\n';
return {};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment