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 << "another instance of this program is running" << endl;			return;		}	}}
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist