Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Initialize EXE
Message
From
24/01/2006 06:47:07
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
24/01/2006 05:12:46
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Miscellaneous
Thread ID:
01089657
Message ID:
01089678
Views:
22
>How can I initialize the EXE file so that one cannot open 2 instances at same time in the same workstation or over the network?
* Main.prg
if IsAppRunning("myUniqueApplicationIdentifier")
 messagebox("One instance of this app is already running")
 return
endif
* ...

Function IsAppRunning
	Lparameters tcSemaphoreName
	Local hsem, lpszSemName
	#Define ERROR_ALREADY_EXISTS 183
	Declare Integer GetLastError In win32API
	Declare Integer CreateSemaphore In WIN32API ;
		string @ lpSemaphoreAttributes, ;
		LONG lInitialCount, ;
		LONG lMaximumCount, ;
		string @ lpName
	hsem = CreateSemaphore(0,0,1,tcSemaphoreName)
	Return (hsem # 0 And GetLastError() == ERROR_ALREADY_EXISTS)
Would do it for a single station.
If you want to do it for all users than lock something for that user (ie: set exclusive on).
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform