473,380 Members | 1,243 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,380 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 1406

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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.