1

When I try to unmap network drive letter mappings using WNetCancelConnection2 (or the depreciated WNetCancelConnection), the thread will block for about 10 seconds before the drive letter is actually unmapped if the file server is unavailable on the network. Is there a faster way to unmap this drive letter if the file server is not (and will not be) available?

Matt
  • 774
  • 1
  • 10
  • 28
  • 1
    `WNetCancelConnection2` is a generic function that loads the MPR dlls and queries them in the order set in "HKLM\SYSTEM\CurrentControlSet\Control\NetworkProvider\ProviderOrder" in order to have the correct provider remove the drive mapping. IIRC, they're queried sequentially, so a particular provider could be a bottleneck. If you know it's an SMB share, you can try [`NetUseDel`](https://learn.microsoft.com/en-us/windows/desktop/api/lmuse/nf-lmuse-netusedel) instead. – Eryk Sun Feb 08 '19 at 20:53

1 Answers1

0

Set the third parameter fForce passed to WNetCancelConnection2 to true. This should immediately terminate the connection. Please be aware that if there are open files or jobs on the connection you might loose data. So it might be a good idea to use a PING or some other means to establish whether the remote computer in online or not.

Olaf Hess
  • 1,453
  • 11
  • 18