|
-
December 2nd, 2008, 08:33 AM
#1
WNetAddConnection2 problem
I try to map a network drive in VB using WNetAddConnection2. I've done it in C++ with no problems, but it won't work in VB. I get an error 487 (Unknown error, I think)
Code:
#Region "External_stuff"
Private Const NO_ERROR As Long = 0
Private Const CONNECT_UPDATE_PROFILE As Long = &H1
Private Const RESOURCETYPE_DISK As Long = &H1
Private Const RESOURCE_GLOBALNET As Long = &H2
Private Const RESOURCEDISPLAYTYPE_SHARE As Long = &H3
Private Const RESOURCEUSAGE_CONNECTABLE As Long = &H1
Private Const RESOURCETYPE_ANY As Long = &H0
Private Const SW_SHOWNORMAL As Long = 1
Private Structure NETRESOURCE
Public dwScope As Long
Public dwType As Long
Public dwDisplayType As Long
Public dwUsage As Long
Public lpLocalName As String
Public lpRemoteName As String
Public lpComment As String
Public lpProvider As String
End Structure
Private Declare Function WNetAddConnection2 Lib "mpr.dll" _
Alias "WNetAddConnection2A" _
(ByVal lpNetResource As NETRESOURCE, _
ByVal lpPassword As String, _
ByVal lpUserName As String, _
ByVal dwFlags As Long) As Long
Private Declare Function WNetCancelConnection2 Lib "mpr.dll" _
Alias "WNetCancelConnection2A" _
(ByVal lpName As String, _
ByVal dwFlags As Long, _
ByVal fForce As Long) As Long
Private Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" _
(ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
#End Region
Private Function ConnectNetDrive(ByVal serverpath As String, ByVal driveletter As String) As Boolean
'attempts to connect to the passed network
'connection to the specified drive.
'ErrInfo=NO_ERROR if sucessful.
Dim NETR As NETRESOURCE
Dim errInfo As Long
NETR = New NETRESOURCE
With NETR
.dwScope = RESOURCE_GLOBALNET
.dwType = RESOURCETYPE_DISK
.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE
.dwUsage = RESOURCEUSAGE_CONNECTABLE
.lpRemoteName = serverpath
.lpLocalName = driveletter
.lpProvider = vbNullString
End With
errInfo = WNetAddConnection2(NETR, TextBox4.Text, TextBox3.Text, 0) 'CONNECT_UPDATE_PROFILE)
'vbNullString, "birchr", CONNECT_UPDATE_PROFILE)
TextBox5.Text = errInfo.ToString()
ConnectNetDrive = errInfo = NO_ERROR
End Function
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
ConnectNetDrive(TextBox2.Text, TextBox1.Text)
End Sub
Any ideas?
Thank you in advance
-
December 2nd, 2008, 09:34 AM
#2
Re: WNetAddConnection2 problem
How does this work ?
(I cant even key it into a VB6 Program)
Code:
#Region "External_stuff"
-
December 2nd, 2008, 09:42 AM
#3
Re: WNetAddConnection2 problem
Hm, actually it is VB .NET 2003 - but I hoped it would be sort of similar. I hope I didn't drop this one in the wrong forum...
-
December 4th, 2008, 05:06 AM
#4
Re: WNetAddConnection2 problem
Seems to me, that a Long in VB6 is an Integer in .net.
Please remember to rate the posts and threads that you find useful.
How can something be both new and improved at the same time?
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
|