Solved

WNetAddConnect & /user:domain\username

Posted on 1998-06-11
2
216 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

813 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

17 Experts available now in Live!

Get 1:1 Help Now