We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


Drive Mapping

DavePlumb asked
Medium Priority
Last Modified: 2008-02-01
This s a re-post of a question from Tuesday that got in the wrong category.  I've tried to include the responses as best I could.

I've got a VB program that reads a database to find the location of a project, and then maps a Drive letter to an NT share.  It works great in 95 (clients are 95, servers are NT), but I'm getting an error code 1326 when I try to run it on an NT client.  I'm pretty sure I've narrowed it down to the way the password is handled, but I don't see any way around it.  According to the Win32API help, the WNetAddConnection call can accept a NULL for the password, and thereby "use the default password".  My problem is that the declare in the Library uses a String for the password, and I can't pass a NULL (which, of course is different than an empty string)  If I use an empty string, the WIN32API help file says wNetAddConnection  "uses no password"

The VB declare for WNetAddConnection:
Private Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszPassword As Variant, ByVal lpszLocalName As String) As Long

My call to WNetAddConnection:
lResult = WNetAddConnection(sProjectPath, "", csDRIVE)

If I could just use a Variant for the password, all would be well, but I can't change the Library.

P.S.  ( I am aware of the WNetAddConnection2 & 3 functions, but I don't think they would make any difference.  They still have the same declares for the password)

Rejected AnswerFrom: alamoDate: Tuesday, July 21 1998 - 11:12AM PDT Well, this should be in the VB area, but migth as well answer it here...

There are a number of ways to handle this. The easiest is to use vbNullString - this is a special value to signal VB to pass 0 rather than a real string.
So your call would be:
lResult = WNetAddConnection(sProjectPath, vbNullString, csDRIVE)
and your Declare would of course have the password as "ByVal lpszPassword As String" not as Variant.

The other way to handle this is to change your declaration to one VB will accept but which still calls the function in the identical manner:

Private Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszPassword As Any, ByVal lpszLocalName As String) As Long

Now you could call either of the following and it would work:
lResult = WNetAddConnection(sProjectPath, 0&, csDRIVE)
lResult = WNetAddConnection(sProjectPath, "password", csDRIVE)

Hope this helps!

Great answer.
However, it didn't fix my problem.  Now the error code I get is
#47 - Invalid address (I'm doing that from memory, so I may not have it right)

In any event, now my problem looks to be that VB won't accept a NULL for the password, which NT wants to use to just pick up the user's default password.  


>In any event, now my problem looks to be that VB won't accept a NULL for the password

Nope, the code I posted passes NULL for password. That's not your problem.

It's more likely that sProjectPath or  csDRIVE are wrong, but you didn't post the portion of code which sets them. What are they?

I should have worded my response more carefully.
I should have said:
It looks like the VB call to WNetAddConnection can't handle a NULL as password.  The  sProjectPath and  csDRIVE  have been working fine under 95 for months.  It's only when I mess with the password parameter that I run into these problems.
I also should not have tried to remeber the error code.  The actual error code is #487 ( I had guessed 47).  This WIN32API.TXT file I have describes this error as:
'   Attempt to access invalid address.

Sorry for the long post, and Thanks for any help.
Watch Question

Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

The class doesn't solve the basic problem - it doesn't allow a null password.

Dave, did you try both declares I posted before? It's the latter (declaring the parameter as byval any and passing 0&) that I consider more reliable - if you only tried the vbNullString one but somehow you don't have a definition for vbNullString it won't work.



I guess I need to attend that Thoroughness class, after all.
I looked at your first response and focused on the vbNullString part.  
I didn't catch  the declare "as Any" part until your latest post.

Once I changed my declare to what you had originally suggested, it worked great!!

Thanks a bunch.  I appreciate your sticking with this, even though it was posted in the wrong place.


Sorry about the points, alamo.
Since your name was on the bottom of the list, I assume you'd get credit.
I was quit surprised when I saw waty's namw flash by, but I didn't know how to recall it.  
I'll mail the sysops.

Sorry guys,
I am new here (since 1 week).
I think, what I can do is posting an answer for Alamo and give the points.

Let me know if it possible.


Dave, the person who has submitted an "Answer" rather than a comment gets the points - and there can be only one answer.

The easiest way to deal with this is for you to grade me on the question in Customer Service, accepting my answer there, instead of having that question deleted. You don't even have to email E-E for that. But it's up to you.

waty, thanks, that's Ok. Your answer was a good one, just not for this specific question. It's not uncommon that people get confused at the user interface here like Dave did, a lot of people have asked them to make it clearer but they never have. Just consider yourself lucky :-)
I'll post a question in this topic are for alamo to award him points.

For your future information when using the site:
When you go to grade a question you have the following options:

1. Grade linda's answer:
   A: Excellent! B: Good! C: Average.
   D: Acceptable. E: Reopen question to other experts.
If the proposed answer is not the one which helped you the most, you choose the option to reopen the question to other experts. And a comment ask the person who you want to award the points to post an answer.  When they post an answer you can then grade them.

Linda Gardner
Customer Service @ Experts Exchange
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.