I want to map to two drives om my pc, sometimes when I restart my pc, I have to go into explorer and map them there, I have this code now, but....
I have try it but I still can not get it to work.
How do you tell it what the drive number is
how do you give it a username and password as there is two map drives.
is the code in the correct place.
how do I get it to work for each drive and what about the ip address of each drive
CODE
#Region "Import Files when pressing button"
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
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 MapDrive(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 = DriveLetter & ":"
strUsername = Nothing '(add parameters to pass this if necessary)
strPassword = Nothing '(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
Private Sub Import_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Import.Click
Dim path1 As String = "Y:\Busres.txt"
Dim path2 As String = "X:\Smeyl.txt"
If File.Exists(path1) AndAlso File.Exists(path2) Then
Cls_MessageBbox.Show("All files were importert", "", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
End If
If (Not File.Exists(path1)) Then
Cls_MessageBbox.Show(path1 & " leër is nie op Busres Server nie." & vbNewLine & vbNewLine & "Maak seker Program het geloop op Server", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Else
My.Computer.FileSystem.MoveFile("Y:\BUSRES.TXT", "C:\Werk\Busres.txt", FileIO.UIOption.AllDialogs, FileIO.UICancelOption.ThrowException)
End If
If (Not File.Exists(path2)) Then
Cls_MessageBbox.Show(path2 & " leër is nie op Busres Server nie." & vbNewLine & vbNewLine & "Maak seker Program het geloop op Server", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Else
My.Computer.FileSystem.MoveFile("X:\SMEYL.TXT", "C:\Werk\SM.txt", FileIO.UIOption.AllDialogs, FileIO.UICancelOption.ThrowException)
End If
End Sub
Public Function UnMapDrive(ByVal DriveLetter As String) As Boolean
Dim rc As Integer
rc = WNetCancelConnection2(DriveLetter & ":", 0, ForceDisconnect)
If rc = 0 Then
Return True
Else
Return False
End If
End Function
This post has been edited by hendrikbez: 20 Aug, 2008 - 12:00 AM