devxlogo

Disable Executing More than One Instance of a Program

Disable Executing More than One Instance of a Program

Sometimes you don’t want to enable the option of running more than one instance of an executable at a time. This can be achieved by using this fragment of code:

 void main(){ HANDLE hMutex = CreateMutex(NULL, FALSE, "programName"); // if Create mutex succeeded	if (hMutex)	{		// if we already have mutex with that name it means another instance isrunning		if (GetLastError() == ERROR_ALREADY_EXISTS)		{			cout 

devx-admin

Share the Post: