[Request][C++] Block running one instance 2 times.

Joined
Nov 30, 2008
Messages
464
Reaction score
92
Hi, well as title says im requesting/asking if is possible to create a DLL that check an specific process, and if that process is opened again, auto close it. Idk if this is possible ia was trying though but i can't find anything so i'll be glad if someone could help me with this.
Thanks.
 
Code:
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved){
	if(fdwReason == DLL_PROCESS_ATTACH){
		try{
			DEP_SYSTEM_POLICY_TYPE isDep = GetSystemDEPPolicy();
			if(isDep == 1){
				MessageBox(NULL, "Windows Data Execution Prevention is currently in AlwaysOn mode. Gunz cannot start. Please consult the games forum for information on fixing this error.", "Error", MB_OK);
				return TRUE;
				}
			if(isDep == 2 || isDep == 3){
				SetProcessDEPPolicy(0);
				}
			}
		catch(...){
				MessageBox(NULL, "Unable to detect current DEP Policy. Consider upgrading your operating system to Windows XP Service Pack 3 or newer. If GunZ does not run normally, please consult the games forum for more information. If you are seeing this warning in error, please let me know about it.", "Warning", MB_OK);
			}
		CreateMutex(NULL, true, "Gunz");
		if(GetLastError() == ERROR_ALREADY_EXISTS){
			MessageBox(NULL, "GunZ is already running. Please terminate the process before starting a new instance.", NULL, MB_OK);
			return TRUE;
			}

I assume you want it for GunZ (As thats your main section), when you inject a DLL it will make the mutex GunZ, therefore not allowing more than one to be opened since it can't do teh same mutex.
 
Back