VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Page 1 of 1
  • You cannot start a new topic
  • Reply Reply

Map Drive Map two Drives om my PC Rate Topic: -----

#1 hendrikbez  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 19-August 08


Dream Kudos: 0

Share |

Map Drive

Post icon  Posted 19 August 2008 - 11:35 PM

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

#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 August 2008 - 12:00 AM

Was This Post Helpful? 0
  • +
  • -


#2 hendrikbez  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 19-August 08


Dream Kudos: 0

Re: Map Drive

Posted 20 August 2008 - 08:07 PM

Any one !!!! Please help me with this code
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1
  • You cannot start a new topic
  • Reply Reply


Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users