techgnome... Connection does not seems to wake up, by trying to use disconnected drive - even when tried via error handling multiple times - tried that, but no success to reconnect share that way.
.. been reading MSDN, found that there are WNetRestoreConnectionW api call.
https://docs.microsoft.com/en-us/windows/desktop/api/winnetwk/nf-winnetwk-wnetrestoreconnectionw
Remarks
The WNetRestoreConnectionW function is not supported on Windows Vista and later.
To call this function, first call the LoadLibrary function to load Mpr.dll. Then call the GetProcAddress function to retrieve the address of the WNetRestoreConnectionW function.
WNetRestoreConnectionW is used by Winlogon to restore all persistent drive mappings during the interactive logon process. The function is also called by the Microsoft Windows Shell to reconnect individual drives at the user's request. This can occur, for example, when a drive fails to reconnect at logon and the user double-clicks the drive under the My Computer virtual folder.
but as the Remark says, 'not supported on Windows Vista and later'. Does this mean, that function is unusable and removed from newer OS's?
Edit: Yes it does...
Run-time error '453': Can't find entry point WNetRestoreConnectionW in mpr.dll
So 'dead end' with WNetRestoreConnectionW api, in Vista and newer OS.
Looked mpr.dll (from W7, W10 and WS2016 boxes) there are;
WNetRestoreAllConnectionsW and WNetRestoreSingleConnectionW api functions, but no MSDN description for these, so these are officially undocumented ones?
Edit: Documented or not, tried WNetRestoreSingleConnectionW, seems to work.
Code:
Option Explicit
'Private Declare Function WNetRestoreConnectionW Lib "mpr.dll" (ByVal hwndParent As Long, ByVal lpDevice As Long) As Long
Private Declare Function WNetRestoreSingleConnectionW Lib "mpr.dll" (ByVal hwndParent As Long, ByVal lpDevice As Long, ByVal bUseUI As Long) As Long
'
Private Sub Command1_Click()
Debug.Print WNetRestoreShare("P:")
End Sub
Public Function WNetRestoreShare(ByVal lpDevice As String) As Long
'WNetRestoreShare = WNetRestoreConnectionW(ByVal 0&, StrPtr(lpDevice)) 'Can't use in Vista and above -> Run-time error '453': Can't find entry point WNetRestoreConnectionW in mpr.dll
WNetRestoreShare = WNetRestoreSingleConnectionW(ByVal 0&, StrPtr(lpDevice), Byval 0&)
End Function