Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Who has a table
Message
De
15/09/2000 13:42:56
 
 
À
15/09/2000 10:01:58
Al Schoen
Surf Technologies, Ltd.
Princeton, New Jersey, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Divers
Thread ID:
00416847
Message ID:
00417054
Vues:
15
>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform