Here is my code, and I cannot get it to work.
I have files that I get from two map drives X and Y. So when I start my pc,
I have to go to explorer and manly map them every time, before I can get the
files on the drives.
Can someone please look at my code, a tell me were do I need to put the drive
info, userid, password in for each drive.
This part is working.
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 importerd", "",
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
This new code and I am not sure how it works. and it must work with my first
part of code
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