test-in-prod
test-in-prod

Reputation: 498

Check running installation in C#

Is there a way to determine if there is an active installation running in C#? For example, some times if you launch 2 MSIs (or setup.exes) at once one of them will say that there is already installation going on in progress. Is there a way to do that in C#? Say, a self-resetting registry key (that system resets) or a mutex?

Upvotes: 2

Views: 1193

Answers (1)

BBoy
BBoy

Reputation: 1113

A mutex is the way to go.

bool isFirst;
Mutex m = new Mutex(false, "MyMutex", out isFirst);

If isFirst is false then there is another process running. As for the name if you want this to check across multiple sessions (terminal sessions) then change the code to something like.

Mutex m = new Mutex(false, "Global\\MyMutex", out isFirst);

Upvotes: 1

Related Questions