Solved

WNetAddConnect & /user:domain\username

Posted on 1998-06-11
2
215 Views
Last Modified: 2008-02-01
Does anyone know how to specify the username and domain for the
WNetAddConnection2 call (or other API)?

For example:

NetR.dwScope = RESOURCE_GLOBALNET
NetR.dwType = RESOURCETYPE_DISK
NetR.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE
NetR.dwUsage = RESOURCEUSAGE_CONNECTABLE
NetR.lpLocalName = "G:"
NetR.lpRemoteName = "\\share"
WNetAddConnection2(NetR, "pass", NULL, CONNECT_UPDATE_PROFILE)

This would be the same as net use G: \\SERVER\share pass
This is fine under 95/98.


But under NT4, I need to specify the domain & username such as

net use G: \\SERVER\share /user:domain\username pass

How do I do this with VB code?  Is there something else other then
WNetAddConnection2 that can do it?

Please help!
0
Comment
Question by:scottg
  • 2
2 Comments
 
LVL 6

Accepted Solution

by:
alamo earned 300 total points
ID: 1463170
The third argument to WNetAddConnection2, which you have set to NULL, is the username.

Good luck!
0
 
LVL 6

Expert Comment

by:alamo
ID: 1463171
I just tried this in a test program, and confirmed that it works.

The one thing I couldn't test is how it processes the "domain\" part of "domain\user". The only machine I have available to test with at the moment is in the same domain as I am, and the connection would succeed even if I put the wrong domain. I am assuming that was because it was trying the default domain when the ine I specified one failed, but I can't prove that. Let me know if you have problems with the domain part, and I will investigate further.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now