简体   繁体   中英

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?

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM