Windows下基于SteamID编程检测Steam游戏运行状态的可行方案
Let's break down practical, consistent solutions to your problem—since the registry Running value is hit-or-miss (looking at you, Rocket League) and tracking just steam.exe doesn't give you the actual game process:
1. Track Game Processes via Command Line Arguments (No SDK Required)
Steam launches nearly all games with a command line that includes the target AppID using the -applaunch flag. You can enumerate all running Windows processes and check their command lines for this flag paired with your target Steam AppID.
Here's a quick PowerShell example (easily adapted to C#/C++ via Windows APIs):
$targetAppID = "252950" # Rocket League's AppID Get-WmiObject Win32_Process | Where-Object { $_.CommandLine -match "-applaunch $targetAppID" -and $_.Name -ne "steam.exe" } | Select-Object Name, ProcessId, CommandLine
This works even if you launch the game via an external program that calls steam.exe—the actual game process will still carry the -applaunch <AppID> parameter in its command line.
2. Use the Steamworks Local API (Most Reliable)
If you can integrate the Steamworks SDK into your program, you can directly query the Steam client for running games linked to a SteamID. The key method here is ISteamApps::GetAppRunningInProcess, which checks if a specific AppID is active in any process owned by the current Steam user.
A simplified C++ snippet:
#include "steam/steam_api.h" bool IsGameRunning(uint32_t appID) { if (!SteamAPI_Init()) return false; CSteamID steamID = SteamUser()->GetSteamID(); uint32 processID; // Returns true if the app is running in a process tied to this SteamID return SteamApps()->GetAppRunningInProcess(appID, &processID); }
This bypasses the registry entirely and talks directly to the Steam client, so it works consistently across all Steam games—even those that ignore the legacy Running registry key.
3. Enumerate Steam.exe Child Processes
When Steam launches a game, the game process is almost always a direct or indirect child of steam.exe. You can:
- Locate all running
steam.exeprocesses - For each, enumerate its child processes using Windows API tools like
CreateToolhelp32Snapshot - Cross-reference those child processes with your target game's known executable name (e.g.,
RocketLeague.exe,Undertale.exe) or check their command lines for the AppID
This is a solid middle ground if you don't want to use the Steamworks SDK but still need to link game processes back to Steam, even when launched externally.
Why the Registry Running Value Fails
That registry entry is a legacy Steam tracking mechanism, and modern games (especially those using newer Steamworks features or custom launchers) don't always update it. Titles like Rocket League use more direct communication with the Steam client instead of writing to that key—so relying on it is never a robust solution.
内容的提问来源于stack exchange,提问作者Roukira

