472,368 Members | 2,666 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,368 software developers and data experts.

Connect to Network With Authentication

Hi all I want to map a network drive. If the user has access to that
site then that path will map automatically. If the user doesnt have any rights
the i need to get the username and pwd from the user by using windows authentication screen. For example the
WNetConnectionDialog shows the mapnetwork drive dialogbox.For example if you open an IE explorer and type the servername which you dont have access

In the mean while I found WNetAddConnection Function can be used to map that drive.

Here is the code I am using.But I am facing one problem

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Private m_WindowsUserName As String
  3. Private m_NetworkPath As String
  4. Private ErrInfo As Long
  5. 'Initialization of Varraibles
  6. 'Private Sub Class_Initialize()
  7. '   MapDrive
  8. 'End Sub
  10. Private Function MapDrive()
  11.     Dim NetR As NETRESOURCE
  12.     Dim MyPass As String, MyUser As String
  13.     NetR.dwScope = RESOURCE_GLOBALNET
  14.     NetR.dwType = RESOURCETYPE_DISK
  15.     NetR.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE
  17.     NetR.lpLocalName = "X:" ' If undefined, Connect with no device
  18.     NetR.lpRemoteName = m_NetworkPath    ' Your valid share
  19.     ' If the MyPass and MyUser arguments are null (use vbNullString), the
  20.     ' user context for the process provides the default user name.
  21.     ErrInfo = WNetAddConnection2(NetR, MyPass, MyUser, _
  24.     If ErrInfo = NO_ERROR Then
  25.         MsgBox "Net Connection Successful!", vbExclamation, "Share Connected"
  26.     Else
  27.         MsgBox GetErrorInfo, vbExclamation, "Share Not Connected"
  28.     End If
  29. End Function
  31. 'Function get the Error description using Error Id
  32. Private Function GetErrorInfo() As String
  33.     If ErrInfo = NO_ERROR Then
  34.     'If no Error do nothing
  35.     ElseIf ErrInfo = ERROR_CANCELLED Then
  36.         GetErrorInfo = "User Cancelled !"
  37.     ElseIf ErrInfo = ERROR_NO_NET_OR_BAD_PATH Then
  38.         GetErrorInfo = "Network Not Found !"
  39.     ElseIf ErrInfo = ERROR_NO_NETWORK Then
  40.         GetErrorInfo = "Network Not Found !"
  42.         GetErrorInfo = "The Network is Already Connect. Please disconnect it and try again !"
  43.     Else
  44.         GetErrorInfo = ErrInfo & " - Net Connection Failed!"
  45.     End If
  46.     If Len(GetErrorInfo) > 0 Then
  47.     GetErrorInfo = "ERROR : " & GetErrorInfo
  48.     End If
  49. End Function
  51. Public Property Get NetWorkPath() As String
  52.     NetWorkPath = m_NetworkPath
  53. End Property
  55. Public Property Let NetWorkPath(ByVal vNewValue As String)
  56.     m_NetworkPath = vNewValue
  57. End Property
  59. Public Function MapRemoteDrive()
  60.     MapDrive
  61. End Function 
But Now I am facing one problem.Even If i have permision to that server it still prompting for username and password .I dont wy.I want to use the default username and password to map the drive.If it doesnt match, it has to dispay the
authentication window.Can some one Help

Thanks in advance
Dec 6 '07 #1
0 1313

Sign in to post your reply or Sign up for a free account.

Similar topics

by: ITM | last post by:
I've installed SQL Server 2000 Developer Edition on a Windows XP Pro SP2 machine. It's installed without any problems. When I try to connect to it from another XP SP2 machine (by creating an...
by: Reza | last post by:
Hello I tried this friday, but didn't get anywhere so trying again Basically, I have a fixed list of people that can access the application in the Intranet, and with the policy of the company the...
by: Oenone | last post by:
Sorry for the cross-post but I've really no idea where this is best suited. I've an ADO.NET application which connects to a SQL Server database. I have spent the entire morning trying to get it...
by: traceable1 | last post by:
I have a couple new servers - Windows 2003 R2 - with SQL Server 2000 SP4 installed. They are all Active/Active clustered instances (my first ones). I am trying to create database links to other...
by: perjorgen | last post by:
Hi, My asp.net can't connect to any sql database when running 1.1 I can connect to databases if I make a windows application and if if I run asp.net 2.0 Other computers have no problem...
by: Pete | last post by:
I have a web asp.net 1.1 app that is using Windows Authentication on an Apache server. I cannot connect across the Intranet to another network even though there is a 'TRUST' setup between the...
by: Mikael Arhelger | last post by:
Hello, This has been posted a few times but still I could not find a way to connect to our database. We run DB2 Express on WIN2K server with XP clients. I can ping inside network and to the...
by: Billy | last post by:
I have read all of the posts regarding this subject as well as 3 "Dummies" guides and I keep having the same problems. I have a very simple multi-user application that has to hit a database. We...
by: Homer | last post by:
Hi, I got "InnerException: Unable to connect to remote server"..."No connection could be made because the target machine actively refused it" when I attempted to send an email through my...
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.