You can programmatically do what net file /close does. Just enable lmshare.h and the link to Netapi32.dll . You have two functions: NetFileEnum to list all open network files (on this computer) and NetFileClose to close them.
A quick (it is assumed that the program runs on the same server and not many open connections, see the last paragraph) and dirty (without error checking) example:
FILE_INFO_2* pFile = NULL; DWORD nRead = 0, nTotal = 0; NetFileEnum( NULL, // servername, NULL means localhost "c:\\directory\\path", // basepath, directory where VB6 program is NULL, // username, searches for all users 2, // level, we just need resource ID (LPBYTE*)pFiles, // bufptr, MAX_PREFERRED_LENGTH, // prefmaxlen, collect as much as possible &nRead, // entriesread, number of entries stored in pFiles &nTotal, // totalentries, ignore this NULL //resume_handle, ignore this ); for (int i=0; i < nRead; ++i) NetFileClose(NULL, pFile[i].fi2_id); NetApiBufferFree(pFile);
Learn more about NetFileEnum and NetFileClose . Note that NetFileEnum may return ERROR_MORE_DATA if more data is available.
Adriano repetti
source share