Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Who has a table
Message
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:
00417058
Vues:
14
>>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
>
>
Or you can do like I do. Call every conceivable user. Have them all say they don't even have the app open. Then discover I had it open all along. <g>
Michael Helms

May the Schwartz be with you.<(©¿©)> -- Mel Brooks
"Someday, and that day may never come, you will be called upon to perform a service" -- Vito Corleone
"Live like there is no tomorrow, Dance like no one is watching, Love like you've never been hurt." -- Anonymous
"I'm thinking about joining the campaign for shorter tag lines." -- Me
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform