mcsdguyian
asked on
.NET Networking Mapping
I need to be able to map some networked drives as persistent and then verify they are mapped. I also need to change a Drive letter from D: to Y: and verify that happens. All needs to be done with preferably with VB.NET using VS2010
Thanks
Ian
Thanks
Ian
ASKER
I am actually trying to get away from using the batch file. This is what I have in place already. I have no way to verify the the mapping happens and it does not always map even though it runs through the code.
I am using the following code to map and unmap the drive:
Public Function MapDrive(ByVal DriveLetter As String, ByVal UNCPath As String) As Boolean
Dim nr As NETRESOURCE
Dim Username As String
Dim Password As String
nr = New NETRESOURCE
nr.lpRemoteName = UNCPath
nr.lpLocalName = DriveLetter & ":"
Username = Nothing '(add parameters to pass this if necessary)
Password = Nothing '(add parameters to pass this if necessary)
nr.dwType = RESOURCETYPE_DISK
Dim result As Integer
result = WNetAddConnection2(nr, Password, Username, 0)
If result = 0 Then
Return True
Else
Return False
End If
End Function
Public Function UnMapDrive(ByVal DriveLetter As String) As Boolean
Dim rc As Integer
rc = WNetCancelConnection2(Driv eLetter, 0, ForceDisconnect)
If rc = 0 Then
Return True
Else
Return False
End If
End Function
The problem I am having though is I need to verify the connection outside of this code. Such as D: = \\folder1\temp\ Versus \\folder2\temp
I also need to figure how to change drive letters
Ian
I am using the following code to map and unmap the drive:
Public Function MapDrive(ByVal DriveLetter As String, ByVal UNCPath As String) As Boolean
Dim nr As NETRESOURCE
Dim Username As String
Dim Password As String
nr = New NETRESOURCE
nr.lpRemoteName = UNCPath
nr.lpLocalName = DriveLetter & ":"
Username = Nothing '(add parameters to pass this if necessary)
Password = Nothing '(add parameters to pass this if necessary)
nr.dwType = RESOURCETYPE_DISK
Dim result As Integer
result = WNetAddConnection2(nr, Password, Username, 0)
If result = 0 Then
Return True
Else
Return False
End If
End Function
Public Function UnMapDrive(ByVal DriveLetter As String) As Boolean
Dim rc As Integer
rc = WNetCancelConnection2(Driv
If rc = 0 Then
Return True
Else
Return False
End If
End Function
The problem I am having though is I need to verify the connection outside of this code. Such as D: = \\folder1\temp\ Versus \\folder2\temp
I also need to figure how to change drive letters
Ian
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
How am I to verify I am connected to where I need to be? Also how would I change a Drive letter from a batch file?
Open in new window
This VB code will fire it off:
Open in new window