|
-
May 11th, 2007, 01:31 PM
#1
Thread Starter
Lively Member
[2005] DRIVE MAPPING PAssing the User ID. (using WNETAddConnection Function )
Hello community,
Im connecting to a mapped drive via a smal app im trying to write.
Im using the WNETAddConnection Function but i noticed it only takes 3 parameters.
I need to pass it my user ID since the Authentication on the server im connectiong to uses a different USer ID for me instead of my systems ID.
Is there a parameter im missing or am i using the correct function??
Code:
Private Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszPassword As String, ByVal lpszLocalName As String) As Long)
VB.Net uber-noob since04, Yeababy! 
-
May 11th, 2007, 01:38 PM
#2
Hyperactive Member
Re: [2005] DRIVE MAPPING PAssing the User ID. (using WNETAddConnection Function )
-
May 11th, 2007, 02:09 PM
#3
Thread Starter
Lively Member
Re: [2005] DRIVE MAPPING PAssing the User ID. (using WNETAddConnection Function )
OK thanks , i see the description so now im building the app but i have another question
I see the new Methods for WNET..2 , the first parm LpNetResource is a structure.
DO i have to populate all of the entrys within that structure or can i just populate the path and letter?
VB.Net uber-noob since04, Yeababy! 
-
May 11th, 2007, 02:43 PM
#4
Hyperactive Member
Re: [2005] DRIVE MAPPING PAssing the User ID. (using WNETAddConnection Function )
Code:
Public Const ForceDisconnect As Integer = 1
Public Const RESOURCETYPE_DISK As Long = &H1
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
Dim nr As NETRESOURCE
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
Try
result = WNetAddConnection2(nr, strPassword, strUsername, 0)
Catch ex As Exception
MessageBox.Show("Error in MapDrive: " & vbCrLf & ex.Message.ToString)
End Try
-
May 11th, 2007, 03:30 PM
#5
Thread Starter
Lively Member
Re: [2005] DRIVE MAPPING PAssing the User ID. (using WNETAddConnection Function )
This is my code, I have looked over it and found no eerors form what everyone has helped with.
My environment is a XPpro system connecting to a Oracle server(unsure of OS nx or ms).
I get no error and my message box returns false as it should since i have not connected. I triple verified my pw and id's to make sure they were correct by watching the values as the app debuged.
any advice would be welcome.
Code:
Public Class Form1
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, ByVal uName As String, ByVal pWord 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 = uName
strPassword = pWord
nr.dwType = RESOURCETYPE_DISK
Dim result As Integer
Try
result = WNetAddConnection2(nr, strPassword, strUsername, 0)
Catch ex As Exception
MessageBox.Show("error: " & vbCrLf & ex.Message.ToString)
End Try
If result = 0 Then
Return True
Else
Return False
End If
End Function
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
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim user As String
Dim passWrd As String
Dim driveLtr As String
Dim pathName As String
user = "YaddaYadda"
passWrd = "YaddaYadda"
driveLtr = "Y"
pathName = "\\Yadda.Yadda\Folder"
If MapDrive(driveLtr, pathName, user, passWrd) = True Then
MessageBox.Show("good")
Else
MessageBox.Show("false")
End If
End Sub
End Class
VB.Net uber-noob since04, Yeababy! 
-
May 11th, 2007, 07:17 PM
#6
Re: [2005] DRIVE MAPPING PAssing the User ID. (using WNETAddConnection Function )
You should note that if a system is already has a mapped drive using user A credentials, you can not map another drive using different credentials... You should try this manually and you'll see what I'm taking about.
-
May 14th, 2007, 07:31 AM
#7
Thread Starter
Lively Member
Re: [2005] DRIVE MAPPING PAssing the User ID. (using WNETAddConnection Function )
OK,
Ill explain my setup. Currently my org is logged into a domain under the following format.
Username[at]sub3.sub2.sub1
and all of our drives our mapped under this context.
the drive i'm trying to reach is :
Username[at]sub2.sub1
I can in fact connect to this drive manualy by typing in the information and User and PW info but when i try to use WNET..2 it fails and also fails with WNET..
The domain is under Novell if im not mistaken, might this have an issue to do with it?
VB.Net uber-noob since04, Yeababy! 
-
May 14th, 2007, 09:43 PM
#8
Re: [2005] DRIVE MAPPING PAssing the User ID. (using WNETAddConnection Function )
Try to map a drive using NET USE command from command prompt. If you succeed, simply write a function to map your drive using a process to start net use....
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
|