1

My goal is to be able to access the name of a process that I know the process name and PID of. I'm not looking for the process name.

That's the general goal but to be clear I'll use the specific example I'm working on. I want to be able to determine the current song being played on Spotify, but can't use the API because I would want to determine it every couple of seconds and I'm not sure it would be a good idea to keep pinging the API (which is how I'm assuming it works).

A solution I can see is that the main app process names itself after the current song in task manager (but it's process name is still spotify.exe) as can be seen here

My question is can I access that specific name, preferably with python? I've also checked powershell tasklist /svc and it isn't used there as a service name.

Thanks

Jeff Vader
  • 11
  • 1
  • Check out [this answer](https://stackoverflow.com/a/3762031/9482608), the recommended module works for Windows. – Mike McCartin Aug 26 '19 at 11:03
  • 1
    Searching for running processes and then accessing them in a way they weren't meant to is a brittle endeavor. You should really use the API. Yes, they have a rate limit, but they also tell you when you hit the rate limit and when it's fine to repeat your request. https://developer.spotify.com/documentation/web-api/#rate-limiting – blubberdiblub Aug 26 '19 at 11:04
  • @MikeMcCartin unfortunately the module doesn't seem to be able to be able to access the "name" that appears in task manager, only the process name (which will always be Spotify.exe) – Jeff Vader Aug 26 '19 at 11:30
  • @blubberdiblub I think I misunderstand you, but I wouldn't be searching for the process or it's PID, just the one name that appears in task manager (knowing PID). I may use the API if I can't access that name, or if the current playing song isn't being held locally on the device. – Jeff Vader Aug 26 '19 at 11:34
  • Well, what I mean is when you do it the way you suggest you're relying on OS behavior (how the OS presents the name to you, which can change with an OS update), on third party application behavior (how the Spotify application presents the song in the application name, which can change on Spotify update) and you still need to reliably retrieve the PID from some place so it still works after you restart Spotify or after you reboot. It's really fine to do it like that for practice and for education purposes, but it's unclean for a more serious application. The clean way is using the API. – blubberdiblub Aug 26 '19 at 11:51
  • @blubberdiblub thanks for clarifying. Fortunately this is only for personal use, but what you mentioned are good for me to keep in mind going forward with anymore serious projects, thanks! – Jeff Vader Aug 26 '19 at 12:24

0 Answers0