Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27329

Problem Mapping Drive on W7

$
0
0
First..... I'm very new to VB.NET -- only a week or so into using it, but have 15 years of using close-sibling LotusScript.

I've inherited a VB & XML program that I'm rewriting purely into VB.NET (while learning VB.NET at the same time). I've lifted a lot of the drive-mapping code from the original VB source, but am having problems getting the drives to map.

The side notes --
1) the original runs fine on XP, but fails on W7
2) I started using #Develop before finding out Microsoft makes a free version of Visual Studio
3) The program as a whole allows users to map a set of desired drives, with available selections built from coded-in division & department lists and the current user's AD group memberships.

Here are the (presumed relevant) code snippets I lifted from the original and adjusted a little --

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 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 Function MapDrive(ByVal DriveLetter As String, ByVal UNCPath As String, ByVal struser As String, ByVal strpass As String) As Integer
Dim objhash = New Dictionary(Of Integer, String)
objhash.Add(5, "Access Denied")
objhash.Add(53, "The network server was not found.")
objhash.Add(66, "ERROR_BAD_DEV_TYPE")
objhash.Add(67, "ERROR_BAD_NET_NAME")
objhash.Add(85, "This computer already has the drive letter assigned that RemoteMapper is trying to use.")
objhash.Add(86, "Bad password or user name.")
objhash.Add(170, "ERROR_BUSY")
objhash.Add(1200, "ERROR_BAD_DEVICE")
objhash.Add(1202, "This drive letter is already mapped. Try disconnecting this drive letter manually before using remote mapper.")
objhash.Add(1203, "The path to the server, supplied by your administrator, cannot be found.")
objhash.Add(1204, "ERROR_BAD_PROVIDER")
objhash.Add(1205, "ERROR_CANNOT_OPEN_PROFILE")
objhash.Add(1206, "ERROR_BAD_PROFILE")
objhash.Add(1208, "ERROR_EXTENDED_ERROR")
objhash.Add(1219, "The account entered conflicts with a drive already mapped to this server.")
objhash.Add(1223, "ERROR_CANCELLED")
objhash.Add(1326, "Invalid Credentials. Either a bad user name or password was entered or your account does not have permissions to this resource.")

Dim nr As NETRESOURCE
Dim strUsername As String
Dim strPassword As String
nr = New NETRESOURCE
nr.lpRemoteName = UNCPath
nr.lpLocalName = DriveLetter + ":"
nr.dwType = &H1 ' RESOURCETYPE_DISK
strUsername = struser
strPassword = strpass

Dim result As Int16 = WNetAddConnection2(nr, strPassword, strUsername, &H0)
If result <> 0 Then
For Each errorCode In objhash.Keys
If errorCode = result Then
MsgBox("While mapping " & DriveLetter & ":" & UNCPath & vbCrLf & "The system received error: " & _
result & vbCrLf & objhash.Item(result), 48, "RemoteMapper Error")
End If
Next
Else
'MsgBox("While mapping " & DriveLetter & ": " & UNCPath & vbCrLf & "The system recieved error: " & result)
End If

End Function

The function call is "Call MapDrive(stDrive, stUNC, IDTextBox.Text, PWTextBox.Text)" .

I'm consistently getting error #67 (ERROR_BAD_NET_NAME), which is frustrating me to no end because the code looks like it should work (based on a few hours of googling for help, which did resolve a couple of other problems and got me to this point).

When I run the overall application, I pre-confirm the ID/PW pair is valid. I can also copy-and-paste the exact UNC Path into a command shell "net use" and manually map the drive.

Any help in spotting my logic, typographical, etc., errors would be greatly appreciated.

Thanks.....

Viewing all articles
Browse latest Browse all 27329

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>