Hi, please try this:
The UserLogging function creates the txt file for user control when it enters the program and deletes it when it exits.
To view all connected users, you can use the ShowConectedUsers function.
( Idea tomada de un usuario aqui en el foro: hmpaquito)
viewtopic.php?f=6&t=16001&hilit=usuarios+conectados&sid=445b23062ba78d3030099d8213c107bf#p82909
//----------------------------------------------------------------
//USUARIOS CONECTADOS -- Francisco J. Alegria P. Sept/2010
//----------------------------------------------------------------
//---------------------------------------------------------------//Ctrl usuarios activos en este programa
Function UserLogging(lNew)
local cDirUserLog := cPathDef+"\USERSLOG"
local cUserLog
local cEquipo:=NetName(.f.)
local nHand, FO_SHARED := 64
If !lIsDir(cDirUserLog) //creamos el sub-dir
lMkDir(cDirUserLog)
Endif
//cNombUser es static, y se toma del fich de usuarios
cUserLog := cDirUserLog+"\"+Substr(cNombUser,1,12)+cEquipo+".log"
If lNew //Entrando
nHand := FCreate( cUserLog )
FWrite(nHand, cNombUser + CRLF+; //usuario del programa
cEquipo + CRLF+"") //nombre del equipo
FClose(nHand)
//Lo abrimos en modo shared. (nHandUserLog es static)
//Cuando se requiere ver los conectados al programa, se trata de abrir en exclusivo,
//y si no se puede, es que el usuario esta conectado al programa. (Ver ShowConnectedUsers())
nHandUserLog := FOpen( cUserLog, FO_SHARED ) // abrimos el fichero compartido
Else //Saliendo
FClose(nHandUserLog)
Ferase(cUserLog)
Endif
Return nil
/* --------------------------------------------------------------------
//Fileio.ch
OPEN MODES:
FO_READ 0 Open file for reading
FO_WRITE 1 Open file for writing
FO_READWRITE 2 Open file for reading and writing
SHARING MODES:
FO_COMPAT 0 Compatibility mode
FO_EXCLUSIVE 16 Exclusive use
FO_DENYWRITE 32 Prevent other applications from writing
FO_DENYREAD 48 Prevent other applications from reading
FO_DENYNONE 64 Allow others to read or write
FO_SHARED 64 Same as FO_DENYNONE
-------------------------------------------------------------------- */
//----------------------//Mostrar usuarios activos en este programa
Function ShowConnectedUsers()
local cDirUserLog := cPathDef+"\USERSLOG"
local aDir := DIRECTORY(cDirUserLog + "\*.*", )
local nHand, aActiveUsers:={}, cLogText, cFich
local cUserName,cComputName
local FO_EXCLUSIVE:=16
AEVAL( aDir, {|aFich| cFich:=cDirUserLog+"\"+aFich[F_NAME],;
if( nHand := FOpen( cFich, FO_EXCLUSIVE ) < 0,; //si no se abre exclusivo es que usuario esta conectado.
( cLogText := MemoRead(cFich),;
cUserName := Trim(MemoLine(cLogText, 254,1)),;
cComputName := Trim(MemoLine(cLogText, 254,2)),;
aadd( aActiveUsers, {cUserName,cComputName} ) ),;
FClose(nHand) ) } )
XBrowse(aActiveUsers,"Usuarios conectados a "+cExeName)
Return nil
Regards.
Francisco J. Alegría P.
Chinandega, Nicaragua.
Fwxh-MySql-TMySql