Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to determine who is using a table.
Message
 
To
29/12/1998 09:39:58
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00171134
Message ID:
00171924
Views:
27
Hi Valentin,

I am using POINTERS.OCX and I am currently doing exactly what you are looking to do.

Remember what Ed Rauh mentioned about having rights. You can take the code below, paste it into a prg file, change the parameters to suit your needs and run it.


*-- parm1 = server
*-- parm2 = datapath as in server
*-- parm3 = username
*-- parm4 = array name to load values retrieved

? GetNetFilesOpened( "\\continuum", "d:\putz\data", "", "aFils" )
?
?
DISPLAY MEMO LIKE aFils*

*******************************
FUNCTION GetNetFilesOpened
*******************************
LPARAMETERS tcServerName, tcBasePath, tcUserName, tcArrayName
*-- This function returns information about open files.
* It returns the files open only if they were
* opened using a share on that computer.
*
*-- It uses:
* - the NetFileEnum Win32 API function
* to retrieve the wanted information from the OS.
* - the Pointers Control to convert the result
* from NetFileEnum to VFP info.
*
*-- Parameters:
* 1. The server name. It can also be a domain name.
* Use an empty string for the current computer.
* Ex: MyServer
* 2. The base path. Only the files in this directory
* (and all subdirectories) will be returned.
* 3. The user name.
* Use an empty string for all users.
* Ex: JoeDoe

LOCAL lcServerName, lcBasePath, lcUserName, lnBufferPointer
LOCAL lnPreferedMaxLength, lnEntriesRead, lnTotalEntries
LOCAL lnResumeHandle, lnError
LOCAL loPointersObject
LOCAL lnI, lcDll
LOCAL llContinue, lnpFileInfo, lnpFileName, lcFileName
LOCAL lnLocks, lnpUserName, lcUserName

*-- Returned values
#DEFINE ERROR_ACCESS_DENIED 5 && The user does not have access to the requested information.
#DEFINE ERROR_INVALID_LEVEL 124 && The value specified for the Level parameter is invalid.
#DEFINE ERROR_MORE_DATA "N/A" && More entries are available. Specify a large enough buffer to receive all entries.
#DEFINE ERROR_NOT_ENOUGH_MEMORY 234 && Insufficient memory is available.
#DEFINE NERR_BufTooSmall 2123 && The supplied buffer is too small.

*-- Release the array if it already exists
RELEASE &tcArrayName.

IF " NT " $ OS()
*-- NetFileEnum() is in NetAPI32.dll on Windows NT
lcDll = "NETAPI32"
ELSE
*-- NetFileEnum() is in SvrAPI.dll on Windows 9x
lcDll = "SVRAPI"
ENDIF

lnError = -1

DECLARE INTEGER NetFileEnum IN &lcDll ;
STRING @ServerName, ;
STRING @BasePath, ;
STRING @UserName, ;
INTEGER nLevel, ;
INTEGER @BufferPointer, ;
INTEGER PreferedMaxLength, ;
INTEGER @EntriesRead, ;
INTEGER @TotalEntries, ;
INTEGER @ResumeHandle

IF " NT " $ OS()
*-- NetApiBufferFree is not defined on Windows 9x
DECLARE INTEGER NetApiBufferFree IN NETAPI32 ;
INTEGER Pointer
ENDIF

*-- This is the structure used by NetFileEnum
* to retrieve the information.
*typedef struct _FILE_INFO_3 {
* DWORD fi3_id;
* DWORD fi3_permissions;
* DWORD fi3_num_locks;
* LPWSTR fi3_pathname;
* LPWSTR fi3_username;} FILE_INFO_3

*-- Instantiate the Pointers control.
SET CLASSLIB TO POINTERS ADDITIVE
loPointersObject = CREATEOBJECT("Pointers")
RELEASE CLASSLIB POINTERS

*-- The server name, the base path and the user name
* must be in Unicode format.
lcServerName = STRCONV(STRCONV(tcServerName + CHR(0), 1), 5)
lcBasePath = STRCONV(STRCONV(tcBasePath + CHR(0), 1), 5)
lcUserName = STRCONV(STRCONV(tcUserName + CHR(0), 1), 5)

lnPreferedMaxLength = 100000000

lnResumeHandle = 0
lnEntriesRead = 0
lnTotalEntries = 0
lnBufferPointer = 0
lnElements = 0

llContinue = .t.
DO WHILE llContinue
lnError = NetFileEnum( ;
lcServerName, ;
lcBasePath, ;
lcUserName, ;
3, ;
@lnBufferPointer, ;
lnPreferedMaxLength, ;
@lnEntriesRead, ;
@lnTotalEntries, ;
@lnResumeHandle)
IF lnEntriesRead = 0
llContinue = .F.
EXIT
ENDIF
IF lnError = 0
* set step on
FOR lnI = 1 TO lnEntriesRead
IF lnI == 1
PUBLIC &tcArrayName.
ENDIF
DIMENSION &tcArrayName[ lnI, 5 ]

lnpFileInfo = lnBufferPointer + (lnI - 1) * 20

*-- Extract the file id.
&tcArrayName[ lnI, 1] = loPointersObject.Converter.DWORDStringToNumber( ;
loPointersObject.GetMemory(lnpFileInfo, 4))

*-- Extract the permissions on this file
&tcArrayName[ lnI, 2] = GetFilePermissions( loPointersObject.Converter.DWORDStringToNumber( ;
loPointersObject.GetMemory(lnpFileInfo + 4, 4)), ";" )

*-- Extract the number of locks on this file.
&tcArrayName[ lnI, 3] = loPointersObject.Converter.DWORDStringToNumber( ;
loPointersObject.GetMemory(lnpFileInfo + 8, 4))

*-- Extract the file name.
lnpFileName = loPointersObject.Converter.DWORDStringToNumber( ;
loPointersObject.GetMemory(lnpFileInfo + 12, 4))
&tcArrayName[ lnI, 4] = loPointersObject.GetMemory(lnpFileName, "U")

*-- Extract the user name that opened the file.
lnpUserName = loPointersObject.Converter.DWORDStringToNumber( ;
loPointersObject.GetMemory(lnpFileInfo + 16, 4))
&tcArrayName[ lnI, 5] = loPointersObject.GetMemory(lnpUserName, "U")

ENDFOR

*-- Free the memory allocated by NetFileEnum
IF (lnBufferPointer <> 0) AND ;
(" NT " $ OS())
NetApiBufferFree(lnBufferPointer)
ENDIF
ELSE
llContinue = .f.
ENDIF
ENDDO

RETURN( lnError )

*********************************
FUNCTION GetFilePermissions( lnPermissions, m.lcDelimiter )
*********************************
LOCAL lnPermElems, lcRetVal

lcRetVal = ""
lnPermElems = 0

IF BitTest(lnPermissions, 0)
lnPermElems = lnPermElems + 1
DIMENSION aPermissions[lnPermElems]
aPermissions[lnPermElems] = "Read"
ENDIF

IF BitTest(lnPermissions, 1)
lnPermElems = lnPermElems + 1
DIMENSION aPermissions[lnPermElems]
aPermissions[lnPermElems] = "Write"
ENDIF

IF BitTest(lnPermissions, 2)
lnPermElems = lnPermElems + 1
DIMENSION aPermissions[lnPermElems]
aPermissions[lnPermElems] = "Create"
ENDIF

IF BitTest(lnPermissions, 3)
lnPermElems = lnPermElems + 1
DIMENSION aPermissions[lnPermElems]
aPermissions[lnPermElems] = "Execute"
ENDIF

IF BitTest(lnPermissions, 4)
lnPermElems = lnPermElems + 1
DIMENSION aPermissions[lnPermElems]
aPermissions[lnPermElems] = "Delete"
ENDIF

IF BitTest(lnPermissions, 5)
lnPermElems = lnPermElems + 1
DIMENSION aPermissions[lnPermElems]
aPermissions[lnPermElems] = "ChangeAttributes"
ENDIF

IF BitTest(lnPermissions, 6)
lnPermElems = lnPermElems + 1
DIMENSION aPermissions[lnPermElems]
aPermissions[lnPermElems] = "ChangeACL"
ENDIF

IF lnPermElems > 0
lcRetVal = SPACE(128)
ArrayToList( @aPermissions, @lcRetVal, m.lcDelimiter )
ENDIF

RETURN( lcRetVal )

*********************************
FUNCTION ArrayToList( aArray, m.lcList, m.lcDelimiter )
*********************************
* This function will take an array and load its contents into
* a string (m.lcList) delimited with the delimiter specified
* in (m.lcDelimiter). The m.lcList needs to be passed by
* reference. Return value is the number of elements processed
* ie: m.lcString = SPACE(256)
* m.lnEntries = ArrayToList( aMyArray, @lcString, "," )
LOCAL m.lnElements, x

m.lnElements = ALEN( aArray, 1 )
m.lcList = ""

FOR x = 1 TO m.lnElements
m.lcList = m.lcList + IIF( !EMPTY( m.lcList ), m.lcDelimiter, "" ) + ALLTRIM( aArray[x] )
ENDFOR

RETURN( m.lnElements )

*********************************
FUNCTION ListToArray( m.lcList, aArray, m.lcDelimiter )
*********************************
* This function takes a list string delimited by m.lcDelimiter and
* creates an array aArray of the values. Return value is the number
* of elements in the final array.
* ie: m.lnEntries = ListToArray( "1,2,3,4,5", "aMyArray", "," )
LOCAL m.lnDelimCount, x, m.lnStartPos, m.lnDelimPos,;
m.lnElements, m.lnEndPos, m.lnWidth

m.lnElements = 0
m.lnDelimCount = OCCURS( m.lcDelimiter, m.lcList )

IF !EMPTY( m.lcList )
PUBLIC &aArray
IF m.lnDelimCount == 0
m.lnElements = m.lnElements + 1
DIMENSION &aArray.[1,1]
&aArray.[1,1] = ALLTRIM(m.lcList)
ELSE
m.lnStartPos = 1
DIMENSION &aArray.[lnDelimCount+1,1]
FOR x = 1 TO m.lnDelimCount
m.lnElements = m.lnElements + 1
m.lnDelimPos = AT( m.lcDelimiter, m.lcList, x )
m.lnEndPos = IIF( m.lnDelimPos == 0, LEN( m.lcList ) + 1, m.lnDelimPos )
m.lnWidth = ( m.lnEndPos - m.lnStartPos )

m.lcValue = ALLTRIM(SUBSTR( m.lcList, m.lnStartPos, m.lnWidth ))
&aArray.[lnElements,1]=lcValue
m.lnStartPos = m.lnDelimPos + 1
ENDFOR
m.lnElements = m.lnElements + 1
&aArray.[lnElements,1]=ALLTRIM(SUBSTR( m.lcList, m.lnStartPos ))
ENDIF
ENDIF

RETURN( m.lnElements )

Good luck!
Juan L. Romero
gcandela@javanet.com
Previous
Reply
Map
View

Click here to load this message in the networking platform