473,406 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 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
  9.  
  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
  16.     NetR.dwUsage = RESOURCEUSAGE_CONNECTABLE
  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, _
  22.    CONNECT_INTERACTIVE Or CONNECT_PROMPT)
  23.     'CONNECT_INTERACTIVE )
  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
  30.  
  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 !"
  41.     ElseIf ErrInfo = ERROR_DEVICE_ALREADY_REMEMBERED Then
  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
  50.  
  51. Public Property Get NetWorkPath() As String
  52.     NetWorkPath = m_NetworkPath
  53. End Property
  54.  
  55. Public Property Let NetWorkPath(ByVal vNewValue As String)
  56.     m_NetworkPath = vNewValue
  57. End Property
  58.  
  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
Dana
Dec 6 '07 #1
0 1416

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

Similar topics

1
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...
3
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...
7
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...
4
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...
1
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...
0
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...
11
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...
1
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...
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.