Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to force reconnection of a network mapped drive?
Message
 
 
To
21/10/2002 13:45:16
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00713586
Message ID:
00713606
Views:
15
Congrats! You have just posted a question that very few can test. < bg > I wonder what the odds of any of those who can test this, are lurking on UT? Just a non-SWAG, but does looping through all the letters F - Z and executing a llReturn = DIRECTORY(lcDir + [:\]) "activate" actual mapped drives so GETDIR() sees them?

If the directory exists, then you could use API to disconnect then reconnect.

FWIW, here are my PROCS to get UNC path from a drive, connect and disconnect a mapping:
   PROCEDURE GetUNCPath
      LPARAMETERS tcPath
      LOCAL lcResult, lcRemoteDevice, lcBuffer, lnSize, lnError
      lcResult = ""
      lcBuffer = SPACE(200) + CHR(0)
      lnSize = LEN(lcBuffer)
      *-------------------------------------------------------------------
      *-- If the user passed in only one character, this will make sure
      *-- the value is correct.
      *-------------------------------------------------------------------
      lcRemoteDevice = LEFT(tcPath,1) + ":"
      *-------------------------------------------------------------------
      *-- Add CHR(0) to the end of the string. This will make finding the
      *-- end of the return value easier to find.
      *-------------------------------------------------------------------
      IF RIGHT(lcRemoteDevice, 1) # CHR(0)
         lcRemoteDevice = lcRemoteDevice + CHR(0)
      ENDIF
      *-------------------------------------------------------------------
      *-- Open the API function
      *-------------------------------------------------------------------
      DECLARE INTEGER WNetGetConnection IN Win32API ;
         STRING @lcRemoteDevice, STRING @lcBuffer, ;
         INTEGER @lnSize
      *-------------------------------------------------------------------
      *-- Send it in and get the return values
      *-------------------------------------------------------------------
      lnError = WNetGetConnection(@lcRemoteDevice, @lcBuffer, @lnSize)
      IF lnError = 0
         lcResult = LEFT(lcBuffer, AT(CHR(0), lcBuffer) - 1)
         *-------------------------------------------------------------------
         *-- I just want the machine name and volume [share name]
         *-------------------------------------------------------------------
         IF AT("\", lcResult, 4) > 0
            lcResult = SUBSTR(lcResult, 1, AT("\", lcResult, 4) - 1)
         ENDIF
      ENDIF
      RETURN lcResult
   ENDPROC
   PROCEDURE CreateDriveMapping
      LPARAMETERS tcDrive, tcUNC
      IF VARTYPE(tcDrive) <> "C" OR EMPTY(tcDrive)
         RETURN .F.
      ENDIF
      IF VARTYPE(tcUNC) <> "C" OR EMPTY(tcUNC)
         RETURN .F.
      ENDIF
      IF NOT DIRECTORY(tcUNC)
         RETURN .F.
      ENDIF
      tcDrive = LEFT(tcDrive, 1) + [:]
      IF DIRECTORY(tcDrive)
         RETURN .T. && or .F., your decision
      ENDIF
      DECLARE INTEGER WNetAddConnection IN WIN32API ;
         STRING @lpszRemoteName, STRING @lpszPassword, STRING @lpszLocalName
      lnRetVal = WNetAddConnection(@tcUNC, 0, @tcDrive)
      RETURN (lnRetVal = 0)
   ENDPROC
   PROCEDURE RemoveDriveMapping
      LPARAMETERS tcDrive
      IF VARTYPE(tcDrive) <> 'C' OR EMPTY(tcDrive)
         RETURN .F.
      ENDIF
      IF DRIVETYPE(tcDrive) <> 4
         RETURN .F.
      ENDIF
      LOCAL lnForce, lnRetVal
      DECLARE INTEGER WNetCancelConnection IN "mpr.dll" ;
         STRING tcDrive, ;
         INTEGER lnForce
      lnForce  = 1   && Force the disconnect, even if files are open
      lnRetVal = WNetCancelConnection(tcDrive, lnForce)
      RETURN (lnRetVal = 0)
   ENDPROC
>GETDIR() doesn't return remoted mapped drives that are mapped, but not connected, as illustrated by their icon having a red X thru it in Explorer. This happens when the computer is started before the computer with the mapping is started before the computer with the drive.
>
>I'd like to show the drive in GETDIR(), by forcing the connection (if possible). If the drive really isn't available, then of course, it shouldn't show.
>
>TIA.
Mark McCasland
Midlothian, TX USA
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform