Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Who has a table
Message
From
15/09/2000 13:42:56
 
 
To
15/09/2000 10:01:58
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Miscellaneous
Thread ID:
00416847
Message ID:
00417054
Views:
16
>Where might I find code or a utility that a VFP application can request who has a particular table open and allow the application to "kill" the file association or connection?

There are a couple of API samples in the files section (FAQ?) here that explain how to do this, but they are a little hairy.

Any method that you find to do this will be a little complicated regarding rights to 'know' this information. IOW, the WNet functions won't return anything if the process running the code doesn't have admin rights on the machine that the files live on.

Knowing this, here is a function I wrote that uses ADSI to query the FileService service to get this information. this code has to be run _on_ the machine that hosts the files, and that machine has to have ADSI installed. ADSI installs with Win2K, or can be installed on WinNT from a download from the MS ADSI page.
FUNCTION WhoHas
LPARA tcFileName
oWS = CREATEOBJECT("WScript.Network")
lcComputer = oWS.ComputerName

CREATE CURSOR Resources (User C(20), Path C(254))
oFileService = GETOBJECT("WinNT://" + lcComputer + "/lanmanserver,Fileservice")

FOR EACH oFile IN oFileService.Resources
	INSERT INTO Resources (User, Path) ;
		VALUES (oFile.User, oFile.Path)
ENDFOR

SELECT User From Resources ;
	WHERE LOWER(Path) = LOWER(tcFileName) ;
	INTO CURSOR HasFile

SELE hasFile
lcHasString = ""

SCAN
	lcHasString = lcHasString + ALLTRIM(User) + ", "
ENDSCAN

IF !EMPTY(lcHasString)
	lcHasString = LEFT(lcHasString, LEN(lcHasString)-2)
	MESSAGEBOX(ALLTRIM(STR(RECCOUNT("Resources"))) + " total files open. " + CHR(13) + ;
			"The following users have the file " + tcFileName + ;
			" open:" + CHR(13) + CHR(13) + lcHasString, 64, "Open Files")
ELSE
	MESSAGEBOX(ALLTRIM(STR(RECCOUNT("Resources"))) + " total files open. " + CHR(13) + ;
				" No user has " + LOWER(tcFileName) + " open.", 64,"")
ENDIF
Erik Moore
Clientelligence
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform