我遇到了映射驱动器的问题。我过去做了很多次,没有映射单个驱动器的问题。这次我试图映射2并遇到问题。我想知道我是否可以看一眼新鲜的眼睛。
现在究竟发生了什么如下。应用程序将驱动器映射到O:很好,但是当它尝试映射时:L没有任何反应。没有错误,没有。
我尝试自己运行L:并没有任何地图。我试过交换它们,没有。
编辑:使用WinForm
功能
Public Declare Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" _
(ByRef lpNetResource As NETRESOURCE, ByVal lpPassword As String, _
ByVal lpUserName As String, ByVal dwFlags As Integer) As Integer
Public Declare Function WNetCancelConnection2 Lib "mpr" Alias "WNetCancelConnection2A" _
(ByVal lpName As String, ByVal dwFlags As Integer, ByVal fForce As Integer) As Integer
<StructLayout(LayoutKind.Sequential)> Public Structure NETRESOURCE
Public dwScope As Integer
Public dwType As Integer
Public dwDisplayType As Integer
Public dwUsage As Integer
Public lpLocalName As String
Public lpRemoteName As String
Public lpComment As String
Public lpProvider As String
End Structure
Public Const ForceDisconnect As Integer = 1
Public Const RESOURCETYPE_DISK As Long = &H1
Public Function MapDrivePri(ByVal DriveLetter As String, ByVal UNCPath As String) As Boolean
Dim nr As NETRESOURCE
Dim strUsername As String
Dim strPassword As String
nr = New NETRESOURCE
nr.lpRemoteName = UNCPath
nr.lpLocalName = "O:"
strUsername = "" '(add parameters to pass this if necessary)
strPassword = "" '(add parameters to pass this if necessary)
nr.dwType = RESOURCETYPE_DISK
Dim result As Integer
result = WNetAddConnection2(nr, strPassword, strUsername, 0)
If result = 0 Then
Return True
Else
Return False
End If
End Function
Public Function MapDriveBku(ByVal DriveLetter As String, ByVal UNCPath As String) As Boolean
Dim nr As NETRESOURCE
Dim strUsername As String
Dim strPassword As String
nr = New NETRESOURCE
nr.lpRemoteName = UNCPath
nr.lpLocalName = "L:"
strUsername = "" '(add parameters to pass this if necessary)
strPassword = "" '(add parameters to pass this if necessary)
nr.dwType = RESOURCETYPE_DISK
Dim result As Integer
result = WNetAddConnection2(nr, strPassword, strUsername, 0)
If result = 0 Then
Return True
Else
Return False
End If
End Function
致电代码:
'Provides the IP
Dim IP = New StoreIdentifier
Dim v = IP.Get4digitStoreNumber(StoreNumber.Text)
Dim s = IP.GetStoreIP(v)
'Adds last octet to the IP
Dim Pip = s & "1"
Dim Bip = s & "2"
'Adds full path
Dim Ppath As String = "\\" & Pip & "\C$"
Dim Bpath As String = "\\" & Bip & "\C$"
'Maps Drives
MapDrivePri("O:\", Ppath)
MapDriveBku("L:\", Bpath)
现在我说的奇怪的部分是O工作正常,L不会。和代码是一样的。
更新 做了一些更多的故障排除我发现了一些东西。
如果它试图映射的IP就像这样:
30年12月10日
它会正常工作。但是,如果IP是这样的:
50年12月10日
它将映射第一个(1)并挂起而不映射第二个(2)
现在我非常困惑......