I am using the following code to make a connection with a network path to get the list of files.
The network path is defiantly correct, and it is possible for me to map a drive manually with the same credentials. Just when running this code, the error: "53" is displayed which means "The network path was not found.".
The error happens suddenly which suggests to me that even the connection is not being made.
Dim nr As New NETRESOURCE
nr.dwType = RESOURCETYPE_DISK
nr.lpRemoteName = "\\fileserver.ourserver.com\"
MessageBox.Show(WNetAddConnection2(nr, "Password", "ourserver.com\User", 0))
The other code is:
Imports System.Runtime.InteropServices
Imports System
Imports System.IO
Public Class Form1
<StructLayout(LayoutKind.Sequential)> _
Private Structure NETRESOURCE
Public dwScope As UInteger
Public dwType As UInteger
Public dwDisplayType As UInteger
Public dwUsage As UInteger
<MarshalAs(UnmanagedType.LPTStr)> _
Public lpLocalName As String
<MarshalAs(UnmanagedType.LPTStr)> _
Public lpRemoteName As String
<MarshalAs(UnmanagedType.LPTStr)> _
Public lpComment As String
<MarshalAs(UnmanagedType.LPTStr)> _
Public lpProvider As String
End Structure
Private Const NO_ERROR As Long = 0
Private Const RESOURCETYPE_DISK As UInteger = 1
<DllImport("mpr.dll", CharSet:=CharSet.Auto)> _
Private Shared Function WNetAddConnection2(ByRef lpNetResource As NETRESOURCE, <[In](), MarshalAs(UnmanagedType.LPTStr)> ByVal lpPassword As String, <[In](), MarshalAs(UnmanagedType.LPTStr)> ByVal lpUserName As String, ByVal dwFlags As UInteger) As UInteger
End Function
<DllImport("mpr.dll", CharSet:=CharSet.Auto)> _
Private Shared Function WNetCancelConnection2(<[In](), MarshalAs(UnmanagedType.LPTStr)> ByVal lpName As String, ByVal dwFlags As UInteger, <MarshalAs(UnmanagedType.Bool)> ByVal fForce As Boolean) As UInteger
End Function
End Class
Unsure why, but adding /IPC$ to the server path now lets me use it again.