I have a VFP8 app that is installed on several pc's. The
data is on a server.

The problem I have is I have 1 user that walks away from
his pc and when he returns he opens the app again from
the windows icon and starts getting record locking errors.

How can you ck to see if a user already has your app open?

TIA

Frank

Re: How do you keep a user from opening a VFP8 app twice? by Pierre

Pierre
Mon Jan 05 17:13:08 CST 2004

Hello Frank,

how about a call to api? There's a API-funtction called FindWindow, you
could use for it.

If the app is already running, the window title is already given, so
the code would be somthing like:



FUNCTION OnceOnly
LOCAL lnHWND, lcTitle, llRetVal

*** Set UP API Calls
*
Declare Integer FindWindow IN Win32Api String, String
Declare BringWindowToTop IN Win32APi Integer

*** Get the current Screen Caption
*
lcTitle = _Screen.Caption

*** Change it to avoid finding THIS instance
*
_Screen.Caption = SYS(3)

*** Now locate another instance
*
lnHWND = FindWindow( NULL, lcTitle )

*** And restore the original caption
*
_Screen.Caption = lcTitle

*** Check the results
*
IF lnHWND > 0
*** We have found something!
*
BringWindowToTop( lnHWND )
*** Set the Return Value
*
llRetVal = .T.
ENDIF

CLEAR DLLS

*** Return Status for action
*
RETURN llRetVal


HTH
Pierre

Re: How do you keep a user from opening a VFP8 app twice? by Tony

Tony
Mon Jan 05 17:44:00 CST 2004

Frank,
I think maybe the guy needs the programming training. You would think
that after he does that a few times he would understand what he is
doing.
Tony

"Frank" <anonymous@discussions.microsoft.com> wrote in message
news:02c901c3d3de$5dc248c0$a601280a@phx.gbl...
I have a VFP8 app that is installed on several pc's. The
data is on a server.

The problem I have is I have 1 user that walks away from
his pc and when he returns he opens the app again from
the windows icon and starts getting record locking errors.

How can you ck to see if a user already has your app open?

TIA

Frank



Re: How do you keep a user from opening a VFP8 app twice? by Rush

Rush
Mon Jan 05 19:04:57 CST 2004

Poor attitude and poor interface. Clicking on the icon is a typical user
action, and should be expected. The program should either start a second
copy (if allowed) or switch to the running copy.

- Rush

"Tony" <sperduti@att.net> wrote in message
news:4FmKb.284528$Ec1.9777534@bgtnsc05-news.ops.worldnet.att.net...
> Frank,
> I think maybe the guy needs the programming training. You would think
> that after he does that a few times he would understand what he is
> doing.
> Tony
>
> "Frank" <anonymous@discussions.microsoft.com> wrote in message
> news:02c901c3d3de$5dc248c0$a601280a@phx.gbl...
> I have a VFP8 app that is installed on several pc's. The
> data is on a server.
>
> The problem I have is I have 1 user that walks away from
> his pc and when he returns he opens the app again from
> the windows icon and starts getting record locking errors.
>
> How can you ck to see if a user already has your app open?
>
> TIA
>
> Frank
>
>



Re: How do you keep a user from opening a VFP8 app twice? by Cindy

Cindy
Mon Jan 05 19:17:57 CST 2004

In news: 02c901c3d3de$5dc248c0$a601280a@phx.gbl,
Frank <anonymous@discussions.microsoft.com> wrote:
> ....he opens the app again from
> the windows icon and starts getting record locking errors.
>
> How can you ck to see if a user already has your app open?

Hi Frank,

Go to www.universalthread.com, click on the Visual FoxPro Zone icon (circles
across the top) and then the Downloads button (second row of circles).
Search for ID 9329, "Run only one instance of an application."

While you're at the UT, have a look around. Basic membership is free.

--
Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
cindy.winegarden@mvps.org www.cindywinegarden.com




Re: How do you keep a user from opening a VFP8 app twice? by John

John
Mon Jan 05 21:02:12 CST 2004

If you are doing the programming, you could have a config.dbf table with a
field called config.isappopen of type logical. When the app runs, check if
the value is set to .t.. If it is, quit the app. If not, run the app and
when the app closes, set the field to .f.. Just an idea.
John.


"Frank" <anonymous@discussions.microsoft.com> wrote in message
news:02c901c3d3de$5dc248c0$a601280a@phx.gbl...
> I have a VFP8 app that is installed on several pc's. The
> data is on a server.
>
> The problem I have is I have 1 user that walks away from
> his pc and when he returns he opens the app again from
> the windows icon and starts getting record locking errors.
>
> How can you ck to see if a user already has your app open?
>
> TIA
>
> Frank



Re: How do you keep a user from opening a VFP8 app twice? by tsmiley

tsmiley
Tue Jan 06 04:24:08 CST 2004

Frank

there are many ways to skin the cat, here is another

You can create a mutex. Since only one mutex can be created on a given
machine with the same name. you can have you program create the mutex with
the first instance and if run again it will exit or restore the first
instance.

I did this very fast so there may be bugs... I did test it once.


Hope this help you.. This may be reinventing the wheel, I believe there is a
class on UniversalThread that I original got this info from.
Sorry for the formating - my browser changed it going from HTML to Plain
text.
Tom Smiley

ps. remove the messagebox if it works.


**** Code for creating and killing a mutex - use to just run one instance

*** Variables you need
Public hMutex,nmutexerror,cFormCaption
Store Int(0) To hMutex,nmutexerror
Store "" To cFormCaption

#Define error_already_exists 183

*** WinApi functions needed
Declare Integer CreateMutex In Win32API String @lpMutexAttributes, String
bInitialOwner,String @lpName
Declare Integer WaitForSingleObject In WIN32API Integer hObject, Integer
dwTimeOut
Declare SHORT ReleaseMutex In Win32API Integer hMutex
Declare Integer FindWindow In Win32API Integer ,String@
Declare SHORT IsIconic In Win32API Integer HWnd
Declare SHORT BringWindowToTop In Win32API Integer HWnd

*** put something like this in your code
If mutexcreate()
Messagebox("Program already running",16,"Cannot run twice") && remove after
testing
quit && exit from the second instance here use quit or return
Else
**** Run you program in here then kill the mutex before exiting

KillMutex() && at end of you code
Endif


**** the 3 main functions needed

Function mutexcreate
Local omutex,lcInitOwner,lcName,lcformcaption
lcformcaption = Sys(0)
lcName = Chrtran(lcformcaption,Space(1),"")
** Simulate a BOOL type equalling TRUE
lcInitOwner = Chr(1)
cFormCaption = lcformcaption
hMutex = CreateMutex(0,lcInitOwner,@lcName)
nmutexerror = GetLastError()
Messagebox("Name: " + lcformcaption,0,"Mutex name") && remove messagebox
after testing
If nmutexerror = error_already_exists
= displayinstance()
Return .T.
Else
Return .F.
Endfunc


Function KillMutex
Local lnResult
If hMutex # 0
lnResult = WaitForSingleObject(hMutex,50) && 50 is time out
If lnResult # 258 && 258 = STATUS_TIMEOUT
lnResult = ReleaseMutex(hMutex)
If (lnResult = 1) && 1 equals Boolean True
lnResult = CloseHandle(hMutex)
Endif
Endif
Endif
Return
Endfunc

Function displayinstance
Local lcformcaption,lnhWnd,llicon
lcformcaption = cFormCaption
lnhWnd = FindWindow(0,@lcformcaption)
If ( .Not. Empty(lnhWnd))
** Determine if the application
* *is minimized ( an icon)
llicon = (IsIconic(lnhWnd) # 0)
If llicon
* *it's an icon , so restore it
= ShowWindow(lnhWnd,9)
Endif
* *make sure it's active
= BringWindowToTop(lnhWnd)
Else
* *this handles applications with dunamic title text bars
= Messagebox("You already have an instance" + " of this Application
Running." + Chr(13) + ;
chr(13) + "Please check your Task Bar",64,"Only One Instance Allowed")
Endif
Endfunc

*** End of Sample



Re: How do you keep a user from opening a VFP8 app twice? by Rush

Rush
Tue Jan 06 09:21:15 CST 2004

The danger her is that if the applications ends abnormally, the flag never
gets set to .F., and you can't get back in.

Instead of using a flag, try using a login table with a single record for
each machine that uses the app. Have the app attempt to do a record lock
[RLOCK()] on that record upon startup, then release it on shutdown. If a
second copy is started, the RLOCK() will fail and appropriate messages could
be displayed. And if the program crashes on one machine, the operating
system will (or should) release the lock.

- Rush

"John" <oglethorpesupply@earthlink.net> wrote in message
news:UypKb.27810$IM3.7984@newsread3.news.atl.earthlink.net...
> If you are doing the programming, you could have a config.dbf table with a
> field called config.isappopen of type logical. When the app runs, check
if
> the value is set to .t.. If it is, quit the app. If not, run the app and
> when the app closes, set the field to .f.. Just an idea.
> John.
>
>
> "Frank" <anonymous@discussions.microsoft.com> wrote in message
> news:02c901c3d3de$5dc248c0$a601280a@phx.gbl...
> > I have a VFP8 app that is installed on several pc's. The
> > data is on a server.
> >
> > The problem I have is I have 1 user that walks away from
> > his pc and when he returns he opens the app again from
> > the windows icon and starts getting record locking errors.
> >
> > How can you ck to see if a user already has your app open?
> >
> > TIA
> >
> > Frank
>
>



Re: How do you keep a user from opening a VFP8 app twice? by John

John
Tue Jan 06 12:31:24 CST 2004

Good point.
In my system, I have a system manager form where I can reset any flags.
John.



"Rush Strong" <rush.strong]@[verizon.net> wrote in message
news:ueqtxgG1DHA.2448@TK2MSFTNGP12.phx.gbl...
> The danger her is that if the applications ends abnormally, the flag never
> gets set to .F., and you can't get back in.
>
> Instead of using a flag, try using a login table with a single record for
> each machine that uses the app. Have the app attempt to do a record lock
> [RLOCK()] on that record upon startup, then release it on shutdown. If a
> second copy is started, the RLOCK() will fail and appropriate messages
could
> be displayed. And if the program crashes on one machine, the operating
> system will (or should) release the lock.
>
> - Rush
>
> "John" <oglethorpesupply@earthlink.net> wrote in message
> news:UypKb.27810$IM3.7984@newsread3.news.atl.earthlink.net...
> > If you are doing the programming, you could have a config.dbf table with
a
> > field called config.isappopen of type logical. When the app runs, check
> if
> > the value is set to .t.. If it is, quit the app. If not, run the app
and
> > when the app closes, set the field to .f.. Just an idea.
> > John.
> >
> >
> > "Frank" <anonymous@discussions.microsoft.com> wrote in message
> > news:02c901c3d3de$5dc248c0$a601280a@phx.gbl...
> > > I have a VFP8 app that is installed on several pc's. The
> > > data is on a server.
> > >
> > > The problem I have is I have 1 user that walks away from
> > > his pc and when he returns he opens the app again from
> > > the windows icon and starts getting record locking errors.
> > >
> > > How can you ck to see if a user already has your app open?
> > >
> > > TIA
> > >
> > > Frank
> >
> >
>
>



Re: How do you keep a user from opening a VFP8 app twice? by swdev2

swdev2
Tue Jan 06 20:37:25 CST 2004

Tony - Programming Training ? Is User - not programmer . So most
programmers have to provide for 'stupid user tricks' - and starting a second
instance of a vfp app is high up there in the list.

Frank - FindWindow API was mentioned - stick with it - it works - and has
worked for about 5 years now.
There were articles in FPA about how to do it - check it out ?? lemme know
how it goes ?
--
mondo regards [Bill]
--
William Sanders / Electronic Filing Group Remove the DOT BOB to reply via
email.
FREE LONG DISTANCE -> mailto:excel-info@efgroup.net
Free Satellite Receivers and installation ->
http://www.vmcsatellite.com/?aid=58456
mySql / VFP / MS-SQL
"Rush Strong" <rush.strong]@[verizon.net> wrote in message
news:OkOZRC$0DHA.2060@TK2MSFTNGP10.phx.gbl...
> Poor attitude and poor interface. Clicking on the icon is a typical user
> action, and should be expected. The program should either start a second
> copy (if allowed) or switch to the running copy.
>
> - Rush
>
> "Tony" <sperduti@att.net> wrote in message
> news:4FmKb.284528$Ec1.9777534@bgtnsc05-news.ops.worldnet.att.net...
> > Frank,
> > I think maybe the guy needs the programming training. You would think
> > that after he does that a few times he would understand what he is
> > doing.
> > Tony
> >
> > "Frank" <anonymous@discussions.microsoft.com> wrote in message
> > news:02c901c3d3de$5dc248c0$a601280a@phx.gbl...
> > I have a VFP8 app that is installed on several pc's. The
> > data is on a server.
> >
> > The problem I have is I have 1 user that walks away from
> > his pc and when he returns he opens the app again from
> > the windows icon and starts getting record locking errors.
> >
> > How can you ck to see if a user already has your app open?
> >
> > TIA
> >
> > Frank
> >
> >
>
>



Re: How do you keep a user from opening a VFP8 app twice? by Tony

Tony
Wed Jan 07 17:42:19 CST 2004

Yep, you are correct. Should have kept my mouth closed. I have run
into the same problem at one site and just told the guy to live with
it and now he does not do that anymore. But again you are correct, a
programmer should code for that. But who does?? When on a network.
Tony

"swdev2" <wsanders.bob@bob.efgroup.com> wrote in message
news:eOJOqnM1DHA.1676@TK2MSFTNGP12.phx.gbl...
Tony - Programming Training ? Is User - not programmer . So most
programmers have to provide for 'stupid user tricks' - and starting a
second
instance of a vfp app is high up there in the list.

Frank - FindWindow API was mentioned - stick with it - it works - and
has
worked for about 5 years now.
There were articles in FPA about how to do it - check it out ?? lemme
know
how it goes ?
--
mondo regards [Bill]
--
William Sanders / Electronic Filing Group Remove the DOT BOB to reply
via
email.
FREE LONG DISTANCE -> mailto:excel-info@efgroup.net
Free Satellite Receivers and installation ->
http://www.vmcsatellite.com/?aid=58456
mySql / VFP / MS-SQL
"Rush Strong" <rush.strong]@[verizon.net> wrote in message
news:OkOZRC$0DHA.2060@TK2MSFTNGP10.phx.gbl...
> Poor attitude and poor interface. Clicking on the icon is a typical
user
> action, and should be expected. The program should either start a
second
> copy (if allowed) or switch to the running copy.
>
> - Rush
>
> "Tony" <sperduti@att.net> wrote in message
> news:4FmKb.284528$Ec1.9777534@bgtnsc05-news.ops.worldnet.att.net...
> > Frank,
> > I think maybe the guy needs the programming training. You would
think
> > that after he does that a few times he would understand what he is
> > doing.
> > Tony
> >
> > "Frank" <anonymous@discussions.microsoft.com> wrote in message
> > news:02c901c3d3de$5dc248c0$a601280a@phx.gbl...
> > I have a VFP8 app that is installed on several pc's. The
> > data is on a server.
> >
> > The problem I have is I have 1 user that walks away from
> > his pc and when he returns he opens the app again from
> > the windows icon and starts getting record locking errors.
> >
> > How can you ck to see if a user already has your app open?
> >
> > TIA
> >
> > Frank
> >
> >
>
>




Re: How do you keep a user from opening a VFP8 app twice? by Mike

Mike
Thu Jan 08 01:37:59 CST 2004

Might it be better to code your app so that it doesn't matter ?

Mike.

Re: How do you keep a user from opening a VFP8 app twice? by Michel

Michel
Thu Jan 08 11:04:30 CST 2004

I've seen a user who tried to open more than 10 copy of the same exe, on the
same machine ! here's what I've done:

for that job, in the Mainform.ini, I store sys(0) to CuserMachine, and
fopen(CuserMachine,12) on the "server" disk (where are all data). then, you
Fwrite() what you need when you want : with a timer, or/and after a user
identification form, or/and after opening tables, etc.. don't forget
fclose()
everytime you need, you verify your flag. one user and one machine=one flag
if that flag is 0 octets, your user has done nothing, and you send him a
messagebox : your app is running, but y're not identified!
if the flag is >0, then you read it as a text file, or with an append in a
dbf, and you know what was doing your user, and what to tell him

I have also 1 dbf to store date and time of logging of each user/machine
(same dbf for all users/machines), a dbf for each user to store machine
login/logoff, a dbf for each machine to store user login/logoff. these are
the last dbf to be updated when the use quit the app, and then i delete the
flag.

on the beginning of mainprg, i verify the flag, and the 3 log_dbf

it runs ...


"Rush Strong" <rush.strong]@[verizon.net> a écrit dans le message de
news:ueqtxgG1DHA.2448@TK2MSFTNGP12.phx.gbl...
> The danger her is that if the applications ends abnormally, the flag never
> gets set to .F., and you can't get back in.
>
> Instead of using a flag, try using a login table with a single record for
> each machine that uses the app. Have the app attempt to do a record lock
> [RLOCK()] on that record upon startup, then release it on shutdown. If a
> second copy is started, the RLOCK() will fail and appropriate messages
could
> be displayed. And if the program crashes on one machine, the operating
> system will (or should) release the lock.
>
> - Rush
>
> "John" <oglethorpesupply@earthlink.net> wrote in message
> news:UypKb.27810$IM3.7984@newsread3.news.atl.earthlink.net...
> > If you are doing the programming, you could have a config.dbf table with
a
> > field called config.isappopen of type logical. When the app runs, check
> if
> > the value is set to .t.. If it is, quit the app. If not, run the app
and
> > when the app closes, set the field to .f.. Just an idea.
> > John.
> >
> >
> > "Frank" <anonymous@discussions.microsoft.com> wrote in message
> > news:02c901c3d3de$5dc248c0$a601280a@phx.gbl...
> > > I have a VFP8 app that is installed on several pc's. The
> > > data is on a server.
> > >
> > > The problem I have is I have 1 user that walks away from
> > > his pc and when he returns he opens the app again from
> > > the windows icon and starts getting record locking errors.
> > >
> > > How can you ck to see if a user already has your app open?
> > >
> > > TIA
> > >
> > > Frank
> >
> >
>
>