|
-
Aug 10th, 2000, 06:25 AM
#1
Thread Starter
New Member
Hi guys,
I'm no pro programmer, and this has me stumped.
I'm trying to write a small control to run through a list of NT share names, mapping each one and getting disk stats which then get passed to a database.
Problem is, I can't get the mapping to work. I'm using the declare below, but it returns 1200 (as opposed to 0,2,6 for Success, Net Err, Bad Pass).
Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszPassword As String, ByVal lpszLocalName As String) As Long
Anybody know what I'm doing wrong? or what the 1200 returned means?
Cheers
-
Aug 10th, 2000, 06:40 AM
#2
Lively Member
You can take a look at this peace of code
Code:
Option Explicit
'Map Netword Drive
Private Declare Function WNetConnectionDialog Lib "mpr.dll" _
(ByVal hwnd As Long, ByVal dwType As Long) As Long
Private Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" _
(ByVal lpszNetPath As String, ByVal lpszPassword As String, _
ByVal lpszLocalName As String) As Long
Private Declare Function WNetCancelConnection Lib "mpr.dll" Alias "WNetCancelConnectionA" _
(ByVal lpszName As String, ByVal bForce As Long) As Long
Const WN_SUCCESS = 0 ' The function was successful.
Const WN_NET_ERROR = 2 ' An error occurred on the network.
Const WN_BAD_PASSWORD = 6 ' The password was invalid.
' Info Drive
Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" _
(ByVal sDrive As String) As Long
Global Const DRIVE_TYPE_UNDTERMINED = 0
Global Const DRIVE_ROOT_NOT_EXIST = 1
Global Const DRIVE_REMOVABLE = 2
Global Const DRIVE_FIXED = 3
Global Const DRIVE_REMOTE = 4
Global Const DRIVE_CDROM = 5
Global Const DRIVE_RAMDISK = 6
Global Const DRIVE_FORCE_CANCEL = 1
Global Const DRIVE_NOT_FORCE_CANCEL = 0
Public Function DriveType(sDrive As String) As String
Dim sDriveName As Integer 'String
sDriveName = GetDriveType(sDrive & ":\")
Select Case sDriveName
Case DRIVE_TYPE_UNDTERMINED
DriveType = "NoType"
Case DRIVE_ROOT_NOT_EXIST
DriveType = "No Drive"
Case DRIVE_CDROM
DriveType = "CD-ROM"
Case DRIVE_FIXED
DriveType = "Hard Disk"
Case DRIVE_RAMDISK
DriveType = "RAM disk"
Case DRIVE_REMOTE
DriveType = "Network Drive"
Case DRIVE_REMOVABLE
DriveType = "Floppy Disk"
End Select
End Function
Public Sub ShowMapDrives(hwnd As Long)
WNetConnectionDialog hwnd, 1
End Sub
Public Function AddConnection(MyShareName As String, MyPWD As String, UseLetter As String) As Integer
On Local Error GoTo AddConnection_Err
Dim OK As Boolean
Select Case DriveType(UseLetter)
Case "Network Drive"
' Here, you can ask for confirmation to cancel the connection
OK = True
If OK Then
CancelConnection UseLetter, DRIVE_FORCE_CANCEL
Else
AddConnection = -1
End If
Case "No Drive"
OK = True
Case Else
OK = False
AddConnection = -1
End Select
If OK Then AddConnection = WNetAddConnection(MyShareName, MyPWD, UseLetter)
AddConnection_End:
Exit Function
AddConnection_Err:
AddConnection = Err
MsgBox Error$
Resume AddConnection_End
End Function
Public Function CancelConnection(DriveLetter As String, Force As Integer) As Integer
On Local Error GoTo CancelConnection_Err
CancelConnection = WNetCancelConnection(DriveLetter, Force)
CancelConnection_End:
Exit Function
CancelConnection_Err:
CancelConnection = Err
MsgBox Error$
Resume CancelConnection_End
End Function
Sample of call
Code:
AddConnection "\\MyPCName\MySharedName","MyPassword","MyDriveLetter:"
CancelConnection "MyDriveLetter:", DRIVE_FORCE_CANCEL
-
Aug 10th, 2000, 07:19 AM
#3
Thread Starter
New Member
Brilliant - worked first time!
Thanks KWell
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|