Jump to content

_Sk_Processcheck


SimpsoN_Bart
 Share

Recommended Posts

Geliştirdiğiniz projelerinize koyabileceğiniz, kendim için geliştirdiğim bir fonksiyon. Programınızdan iki tane açılmasını önler eğer açıksa size sorar. Mutex çalışma prensibine benzer bir yapısı bulunmaktadır.


#RequireAdmin
$Form1 = GUICreate("Form1", 318, 190)
GUISetState(@SW_SHOW)

_SK_ProcessCheck('TNCTR', $Form1)

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case -3
			Exit
	EndSwitch
WEnd


Func _SK_ProcessCheck($UNIQUENAME, $PROGRAMNAME, $CONFIRM = 7)
	DllCall('kernel32.dll', 'int', 'CreateSemaphore', 'int', 0, 'long', 1, 'long', 1, 'str', $UNIQUENAME)
	Local $GETLASTERROR = DllCall('kernel32.dll', 'int', 'GetLastError'), $ERROR_ALREADY_EXISTS = 183
	If $GETLASTERROR[0] = $ERROR_ALREADY_EXISTS And $CONFIRM = 7 Then
		$CONFIRM = MsgBox(16 + 4, $PROGRAMNAME, 'Bu programın bir örneği zaten çalışıyor! Yeni bir örneğini daha açmak ister misiniz?','',$PROGRAMNAME)
		If $CONFIRM = 6 Then
			Return
		Else
			Exit
		EndIf
		AutoItWinSetTitle($PROGRAMNAME)
		WinActivate($PROGRAMNAME)
	EndIf
EndFunc   ;==>_SK_ProcessCheck()

https://www.box.com/s/qymb7inswlhlurpze7kn

Ayrıca Bkz:

http://www.tnctr.com/topic/204059-singleton-v2/ 

MSDN Kaynağı:

http://msdn.microsoft.com/en-us/library/aa911525.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682438(v=vs.85).aspx 

Kolay Gelsin..

Edited by SimpsoN_Bart
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...