الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

منع المستخدم من فتح اكثر من نسخة لنفس البرنامج في الدلفي

بدأه khalilsoft في 3 أغسطس 2009 · 6 رد · 1,911 مشاهدة · في لغة Delphi
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

بسم الله الرجمان الرحيم

السلام عليكم ورحمة الله وبركاته

اخوتي الاحبة انا عملت برنامج قواعدة بيانات كل شيء تمام

لم يبقى لي سوى ان امنع المستخدم من فتح اكثر من نسخة لنفس البرنامج

من لديه حل لهذه المشكلة ارجوا منه ان يساعدني

وادعوا الله ان يجعله في ميزان حسناته

وشكرا

#2

اخي الكريم هناك خاصية تدعى البحث في المنتدى لماذا لاتستعملها :wacko: :blink: :S

على كل حال انظر هذا البرنامج فيه الخاصية التي تبحث عنها

و اذا اردت التعمق ابحث ال Mutex و كيفية استعمالها ......

عزيزي :

لاتنسى ان تصلي على حبيبنا و شفيعنا يوم لا ينفع مال ولا بنون .

فاللهمّ صّل وسّلم على سيدي و شفيعي وحبيبي محمد عليك الف صلاة وازكى تسليم

*****

2_header.png

#3

وعليكم السلام ورحمة الله وبركاته

أخي الكريم، إقرأ جيدا هذا الكود

//1. CreateMutex



unit Unit1;

uses
Windows, Dialogs, Sysutils;

{....}
implementation

{....}

var
mHandle: THandle; // Mutexhandle

initialization
mHandle := CreateMutex(nil, True, 'XYZ');
if GetLastError = ERROR_ALREADY_EXISTS then
begin
ShowMessage('Program is already running!');
halt;
end;

finalization
if mHandle <> 0 then CloseHandle(mHandle)
end.

{
HANDLE CreateMutex(LPSECURITY_ATTRIBUTES lpMutexAttributes,
BOOL bInitialOwner,
LPCTSTR lpName);

lpMutexAttributes:
Ignored. Must be NULL.

bInitialOwner:
Boolean that specifies the initial owner of the mutex object.
If this value is TRUE and the caller created the mutex,
the calling thread obtains ownership of the mutex object.
Otherwise, the calling thread does not obtain ownership of the mutex.

lpName:
Long pointer to a null-terminated string specifying the name of the mutex object.
The name is limited to MAX_PATH characters and can contain any character except the
backslash path-separator character (\). Name comparison is case sensitive.

Return Values:
A handle to the mutex object indicates success.
If the named mutex object existed before the function call,
the function returns a handle to the existing object and GetLastError
returns ERROR_ALREADY_EXISTS.

}

{******************************************************************}

// 2. CreateSemaphore
// (Alternative Funtion, Alternative Funktion)

procedure TForm1.FormCreate(Sender: TObject);
var
Sem: THandle;
begin
Sem := CreateSemaphore(nil, 0, 1, 'PROGRAM_NAME');
if ((Sem <> 0) and (GetLastError = ERROR_ALREADY_EXISTS)) then
begin
CloseHandle(Sem);
ShowMessage('This program is already running.');
Halt;
end;
end;

{
HANDLE CreateSemaphore(
LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, // SD
LONG lInitialCount, // initial count
LONG lMaximumCount, // maximum count
LPCTSTR lpName // object name
);

lpSemaphoreAttributes:
[in] Pointer to a structure that determines whether the returned handle
can be inherited by child processes.
If lpSemaphoreAttributes is NULL, the handle cannot be inherited.

lInitialCount:
[in] Specifies an initial count for the semaphore object.
This value must be greater than or equal to zero and less
than or equal to lMaximumCount.

lMaximumCount:
[in] Specifies the maximum count for the semaphore object.
This value must be greater than zero.

lpName
[in] Pointer to a null-terminated string specifying the name
of the semaphore object. The name is limited to MAX_PATH characters.
Name comparison is case sensitive.
}

{******************************************************************}

// 3: GlobalFindAtom, GlobalAddAtom

{
This sample shows how to determine if your program was
running in a current session of Windows
It can be usefull if you want ie. to limit your program (a demo)
to run only once per session. It can be stimulating for a registering. :
}

// Place in FormShow event:

procedure TForm1.FormCreate(Sender: TObject);
var
atom: Integer;
CRLF: string;
begin
if GlobalFindAtom('A Text used to be stored in memory') = 0 then
atom := GlobalAddAtom('A Text used to be stored in memory')
else
begin
CRLF := #10 + #13;
ShowMessage('This version may only be run once for every Windows Session.' +
CRLF +
'To run this program again, you need to restart Windows, or better yet:' +
CRLF +
'REGISTER !!');
Close;
end;
end;

// All you had to do was to write some "your" text and
// save it in the Windows global atom table.

#4

اخي kachwahed حاول الابتعاد عن استعمال ال Semaphore في هكذا مواقف وخاصة اذا كان استعمالها في مكان واحد مع ال OS MSGs Sending او ال Muti-Threading .

على كل حال بارك الله اخيkachwahed مااجمل المحاولة واجمل مافيها الثبات .

اخوك محمد

تم تعديل هذه المشاركة بواسطة mohfa في 3 أغسطس 2009 في 21:11

عزيزي :

لاتنسى ان تصلي على حبيبنا و شفيعنا يوم لا ينفع مال ولا بنون .

فاللهمّ صّل وسّلم على سيدي و شفيعي وحبيبي محمد عليك الف صلاة وازكى تسليم

*****

2_header.png

#6

قبل كل شيء السلام عليكم ...لكي نسمح بتنفيد نسخة واحدة للبرنامج ربما نستطيع ربطه بالرجيستري عند تشغيل البرنامج نقوم بانشاء اسم للبرنامج في الرجيستري مع وضع القيمة مثلا1 للدلالة على انه في وضعية تنفيد وهذا كله طبعا للمرة الأولى اما عند تنفيده من جديد يبحث عن القيمة في الريجيستري ان كانت 0 ينفد البرنامج اما ان كانت 1 يطبع رسالة تمنعك من تنفيده مرة اخرى لانه في وضعية تنفيد.....................عند الإغلاق تعود القيمة1 الى 0

#7

السلام عليكم ..

ليس بالضرورة ان تستعمل ال mutex هناك الف طريقة و طريقة :D

راجع الرابط

الرابط الخاص بي

العمل كثير و الوقت قليل أعاننا الله

seo zen SEO Enlightment amazon danbo

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…