It is currently April 19th, 2024, 7:13 pm

Check if Process is Running

Tips and Tricks from the Rainmeter Community
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Check if Process is Running

Post by jsmorley »

This is how to use Perfmon to find out if a particular process is running.

Code: Select all

;===========================================
;  Rainmeter configuration file
;===========================================

[Rainmeter]
Author=JSMorley
Update=500
BackgroundMode=2
SolidColor=0,0,0,1
DynamicWindowSize=1

[Variables]
ProcessName="winamp"

[MeasureProcessPID]
Measure=Plugin
Plugin=Perfmon.dll
PerfMonObject="Process"
PerfMonCounter="ID Process"
PerfMonInstance=#ProcessName#
PerfMonDifference=0

[CalcTranslatePIDToRunningState]
Measure=Calc
Formula=MeasureProcessPID > 0 ? 1 : 0

[MeterIsProcessRunning]
Meter=String
MeasureName=CalcTranslatePIDToRunningState
FontSize=13
FontColor=255,255,255,255
Text=#ProcessName# is running (0/1): %1
Note:

* Don't depend on the PID for anything other than this, as a new, different one is given out each time the process is run.
* ProcessName is the name of the "process", not the "Window". Process names are generally the name of the .exe without the ".exe", but some internal processes that are run by dll files can be found in taskmanager or Process Explorer.
* PerfMonDifference=0 is critical to this. The PID never changes while the process is running so PerfMonDifference=1 (the default) will always return "0"
Squand
Posts: 2
Joined: July 23rd, 2010, 6:27 pm

Re: Check if Process is Running

Post by Squand »

Wow i was just playing with making a .exe file in c# last night which would do this :o and then i was going to make a button on my desktop link to that exe! Saved me a lot of hassle trying to get mine to work!

Know if there is a way to restore a window if it is in the system tray? As that is the main issue which was eluding me!
brbk4498
Posts: 9
Joined: June 8th, 2010, 10:53 pm

Re: Check if Process is Running

Post by brbk4498 »

lol i had something similar to this but urs is more advanced lolz. thanks for the share
H.Seldon
Posts: 4
Joined: July 29th, 2010, 7:33 am

Re: Check if Process is Running

Post by H.Seldon »

If anyone is interested, you can do the same from a batch file:

@echo off
tasklist /nh /fi "imagename eq winamp.exe" | findstr /i "winamp.exe" > nul
if errorlevel 1 goto NOT
echo Winamp is running.
goto END

:NOT
echo Winamp is not running.

:END
User avatar
Alex2539
Rainmeter Sage
Posts: 642
Joined: July 19th, 2009, 5:59 am
Location: Montreal, QC, Canada

Re: Check if Process is Running

Post by Alex2539 »

True, but given that one of Rainmeter's primary focuses is the aesthetic, it may not be desirable to have a command prompt window popping up all the time.
ImageImageImageImage