I am trying to make my app run only once on a computer, My app needs to comunicate to a webservice so it is bad to let it run more than once, currently im using Mutex with this:
MyMsg := RegisterWindowMessage('My_Unique_App_Message_Name');
Mutex := CreateMutex(nil, True, 'My_Unique_Application_Mutex_Name');
if (Mutex = 0) OR (GetLastError = ERROR_ALREADY_EXISTS) then
exit;
Currently this works to limit 1 instance of application per user, but my app is being used in a Windows Server Environment where there are 20+ users loged in at a time, so i need to strict it to only run once per server, what i am trying to do is to declare that Mutex as a Global mutex but i fail to do so when i do the next code it doesnt work at all.
MyMsg := RegisterWindowMessage('My_Unique_App_Message_Name');
Mutex := CreateMutex(nil, True, 'GlobalMy_Unique_Application_Mutex_Name');
if (Mutex = 0) OR (GetLastError = ERROR_ALREADY_EXISTS) then
begin
exit
So am i doing something wrong? is there any other reliable way of not letting a second instance of my app to run?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…